Order of Execution in Salesforce
Why Order of Execution is Important
Understanding the Order of Execution is critical for any Salesforce Administrator because it determines how Salesforce processes a record when it is saved. When multiple automation tools like workflows, process builders, flows, validation rules, and triggers all act on the same record, knowing the sequence in which they fire helps you predict system behavior, troubleshoot issues, and design efficient solutions. Misunderstanding this order can lead to unexpected errors, infinite loops, or data integrity problems.
What is Order of Execution?
Order of Execution refers to the specific sequence of events that Salesforce follows when a record is saved to the database. This includes everything from loading the original record, running system validations, executing before triggers, running custom validation rules, firing after triggers, processing workflow rules, and finally committing the record to the database. Each step occurs in a predetermined order that Salesforce strictly follows.
How Order of Execution Works
Here is the simplified sequence of events when a record is saved:
1. System Validation Rules - Salesforce loads the original record and runs system validation rules to check required fields at the layout level.
2. Before Triggers Execute - All before triggers on the record fire, allowing field values to be changed before the record is saved.
3. Custom Validation Rules - Custom validation rules are evaluated after before triggers complete.
4. Duplicate Rules - The system checks for duplicate records based on configured duplicate rules.
5. Record Saved to Database - The record is saved but not yet committed to the database.
6. After Triggers Execute - After triggers fire, which are commonly used for operations on related records.
7. Assignment Rules - Lead and case assignment rules are evaluated.
8. Auto-Response Rules - Auto-response rules execute for leads and cases.
9. Workflow Rules - Workflow rules are evaluated and their actions execute. If a field update occurs, before and after triggers fire again.
10. Processes and Flows - Process Builder processes and record-triggered flows execute.
11. Escalation Rules - Escalation rules are evaluated.
12. Roll-Up Summary Fields - Parent roll-up summary fields are calculated and updated.
13. Criteria-Based Sharing Rules - Sharing rules are evaluated.
14. Commit to Database - All changes are committed to the database.
Key Points to Remember
- Before triggers run before validation rules, so you can use them to set default values that pass validation.
- Workflow field updates cause triggers to fire again, which can create recursion.
- Validation rules block the save if they fail, preventing subsequent automation from running.
- Roll-up summary field updates on parent records can trigger the parent record order of execution.
Exam Tips: Answering Questions on Order of Execution
Memorize the sequence: Know that before triggers come before validation rules, and workflow rules come after triggers. This is frequently tested.
Watch for recursion scenarios: Questions often present situations where workflow field updates cause triggers to fire multiple times. Recognize these patterns.
Understand the impact of validation failures: If a validation rule fails, no subsequent automation will execute. Look for answer choices that acknowledge this stopping point.
Pay attention to field update timing: Before triggers can modify field values on the current record efficiently. After triggers are better for modifying related records.
Read scenarios carefully: Exam questions may describe multiple automations and ask what happens first or why something fails. Map the scenario to the order of execution sequence.
Eliminate wrong answers: If an answer suggests that workflow rules fire before triggers, you can eliminate it based on your knowledge of the correct sequence.
Practice with real scenarios: Create test records in a sandbox with multiple automations to see the order in action. Practical experience reinforces theoretical knowledge.