Salesforce Order Of Execution
The order of execution is salesforce refers to the order in which the automations/triggers etc. are called when we insert or update a new record into the database.
Here is what the order of execution is:
- Original record loaded from the database or initializes the record for an upsert statement.
- A new record field value is loaded and overwrites the old values. If the record was saved from the UI, performs field length and type validations.
- Executes flows that make before-save updates.
- All before triggers executed.
- System validation steps like verifying all required fields run again, and run any user-defined validation rules.
- Executes duplicate rules. If a duplicate is identified, the record is not saved and no further steps like after triggers and workflow rules are taken.
- Saves the record into database, but doesn’t commit yet.
- All after triggers are executed.
- All assignment rules are executed.
- Auto-response rules are executed.
- Workflow rules executed.
- If there are workflow field updates, update process applies again on record.
- If the record is updated with workflow field update than before update triggers and after update triggers are fired once more in addition to standard validations. Functionalities which do not run once again are: Custom validation rules, flows, duplicate rules, processes, and escalation rules.
- All Processes and flows which are launched via processes and flow trigger workflow actions are executed.
- When a process or flow executes a DML operation, the affected record would have the save procedure again.
- Escalation rules are executed.
- Entitlement rules are executed.
- If the record has a roll-up summary or record is part of cross-object workflow, calculations performed and the roll-up summary field in the parent record is updated than Parent record at the same time have the save procedure.
- If parent record is updated, and grandparent record contains a roll-up summary or is part of a cross-object workflow, calculations performed and roll-up summary in the grandparent record is updated. Grandparent record have the save procedure.
- Criteria Based Sharing rules are executed.
- All DML operations committed to database.
- Post-commit logic, such as sending email etc is executed.