Thursday, April 18, 2013

Triggers and Order of Execution


Few days back I faced a situation , in which it was needed to update a field depending upon a Roll-up Summary field Value through trigger.
FYI we can not get the RollUpSummary field value inside trigger, because of sequence of execution of trigger(after, before) & RollUpSummary field value.

So here I am posting sequence of Trigger , automation rules ,validation rule etc execution in Salesforce.com .
The following is the order salesforce logic is applied to a record.

1- Old record loaded from database (or initialized for new inserts)
2- New record values overwrite old values
3- System Validation Rules
4- All Apex “before” triggers 
5- Custom Validation Rules
6- Record saved to database (but not committed)
7- Record reloaded from database
8- All Apex “after” triggers 
9- Assignment rules
10- Auto-response rules
11- Workflow rules
12- Escalation rules
13- Parent Rollup Summary Formula value updated (if present)
14- Database commit
15- Post-commit logic (sending email)

For Detail explanation please refer
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_order_of_execution.htm 

notes: There is no way to control the order of execution within each group above

No comments:

Post a Comment