Thursday, January 23, 2014

When to use Before Trigger and After trigger in Salesforce

When to use Before Trigger and After trigger in Salesforce?

Before Apex Trigger:-
In case of validation check in the same object.
Insert or update the same object. 
Modify the Values based on the Business Requirement (Ex Country value = US, then automatically fill the zipcode)

After Apex Trigger:-
Insert/Update related object, not the same object.
Notification email.
We cannot use After trigger, if we want to update a record because it causes read only error. This is because after inserting or updating, we cannot update a record.
For instance, if you’re getting an error message Like "System.FinalException: Record is read-only".

1 comment:

  1. Excellent work, I have readied at least eight posts of your website and let me tell you, your website provides the most fascinating information. It’s really helpful who are looking for Salesforce. The Author has explained when to use before Trigger and After Trigger in Salesforce. Salesforce is a highly complex application that can be configured to do practically anything. For More Info: https://goo.gl/z6uyuj

    ReplyDelete