Become a Salesforce Order of Execution Hero
In this post we will talk about how to become an Order of execution Hero!
What is Order of Execution in Salesforce
Order of execution is a set of rules that describe the path a record takes through all automations and the events that happen when you save a record with an insert, update, or upsert statement.
Many people struggle to remember the order of execution which starts with a DML (insert, update or delete). The diagram below provides a nice visual reference.
Source: Daniel Stange and Marc B Kirsch
Order of Execution
When you save a record with an insert, update, or upsert statement, Salesforce performs the following events in this order:
Loads Initial record.
If the request came from a standard UI edit page, Salesforce runs system validation to check the record for page layout specific rules, field definition, and maximum field length.
Executes flows that make a “before-save” update (new change in Winter 20).
Executes all before triggers.
Runs most custom validation rules.
Executes duplicate rules.
Saves the record to the database, but doesn’t commit yet.
Executes all after triggers.
Executes auto-response rules.
Executes workflow rules.
If there are workflow field updates, then it updates the record again.
If the Workflow field updates introduced new duplicate field values, executes duplicate rules again.
If the record was updated with workflow field updates, it fires before and after update triggers one more time (and only one more time) in addition to standard validation.
Custom validation rules are not run again.
Executes processes and flow.
Executes entitlement rules.
Executes record-triggered flows that are configured to run after the record is saved.
If the record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the parent record. Parent record goes through save procedure.
If the parent record is updated, and a grandparent record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the grandparent record. Grandparent record goes through save procedure.
Executes Criteria Based Sharing evaluation.
Commits all DML operations to the database.
Executes all after-commit logic, such as sending email.
Post Source Link