Development questions
What is the exact Order of Execution in Salesforce when a record is saved?
Simplified order for a record save:
- Load original record (or initialize for insert)
- Overwrite with new values; run system validation
- Run before-save record-triggered flows
- Run before triggers
- Run most system validation again, then custom validation rules
- Run duplicate rules
- Save record to the database (not committed)
- Run after triggers
- Run assignment rules, auto-response rules
- Run workflow rules (field updates can re-fire before/after update triggers once)
- Run escalation rules, after-save record-triggered flows
- Run entitlement rules
- Roll-up summary / cross-object formula recalculation on parents
- Criteria-based sharing evaluation
- Commit to the database
- Post-commit: email, async work (future, queueable), platform events
Knowing this helps debug conflicts between flows, validations and triggers.
apex-triggertriggerorder-of-execution
More Development questions
- What is an Apex Trigger in Salesforce and when should you use it over Flows?
- What is the difference between before triggers and after triggers?
- Explain all Trigger context variables (isInsert, isUpdate, isDelete, isUndelete, isBefore, isAfter, isExecuting, size, operationType).
- What is the difference between Trigger.new and Trigger.old?
- In which trigger events are Trigger.new and Trigger.newMap available?
- In which trigger events are Trigger.old and Trigger.oldMap available?