0% found this document useful (0 votes)
15 views2 pages

Apex Trigger Ten Examples

Uploaded by

Rajat Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Apex Trigger Ten Examples

Uploaded by

Rajat Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Nripesh Kumar Joshi (Salesforce Developer)

Custom Validation rule from Trigger

Ten Apex Trigger Examples

Scenario 1: Prevent Account Deletion with Open Opportunities

Problem: Before Delete on Account, prevent deletion if there are open opportunities related to
the account.

Scenario 2: Require Opportunity Amount for Closed Won

Problem: Make sure the Amount field is populated when the opportunity stage is set to
"Closed Won."

Scenario 3: Validate Product Quantity on Opportunity

Problem: Before Insert or Before Update on Opportunity, ensure that the product quantity is
greater than 0.

Scenario 4: Enforce Minimum Opportunity Close Date

Problem: Before Insert or Before Update on Opportunity, ensure the close date is not earlier
than a certain date.

Scenarios 5: Enforce Unique Opportunity Names

Problem: Ensure that no two opportunities have the same name.(duplicate Opportunity by
name)

Scenario 6: Duplicate check based on fields

Problem: Write a trigger on lead to prevent duplicate records based on lead email, if a record
already created with the same Email, or record is Updated. The trigger should throw an error.

Scenario 7: Duplicate check based on fields (Phone field Or Name field)

Problem: Write Apex trigger on Account to avoid creation of duplicate record if the account
with same phone exists in the system in Salesforce.

Scenario 8: Enforce the business logic for insertion (Related contact should not be more than
2)

Problem: Write a trigger on account. "An account should not have more than 2 contacts
associated with it"

Scenario 9: Limit record creation based on user profile

Problem: Before insert on custom object, limit the number of records that user with specific
profile can create the record.

Scenario 10: Prevent lead conversion without required information

Problem : Before Update on Lead, prevent conversion if essential information is missing


( Required field -Company, FirstName and LastName)

You might also like