Order of Execution
What happens, step by step, when a record is saved — and why it matters for triggers, flows and validation rules.
Developer 2 min readOrder of executionTriggersFlowValidation rules
Knowing the save order lets you answer "why didn't my validation rule see the value my trigger set?" style questions.
The sequence (simplified)
- Load the original record (update) or initialize new values (insert).
- System validation — required fields, field formats, max length (and layout rules from the UI).
- Before-save record-triggered flows (fast field updates).
- Before triggers (
before insert/before update/before delete). - System validation again + custom validation rules.
- Duplicate rules.
- Record saved to the database (not committed yet).
- After triggers.
- Assignment rules → auto-response rules.
- Workflow rules — field updates here re-run before/after update triggers once more.
- Escalation rules.
- After-save record-triggered flows (and other flow automation).
- Entitlement rules.
- Roll-up summary recalculation on the parent (the parent goes through its own save).
- Criteria-based sharing evaluation.
- Commit to the database.
- Post-commit: emails sent, async Apex (
@future, queueable) and outbound messages start.
Consequences you should be able to explain
- A before-save flow runs before your before trigger — your trigger sees the flow's changes.
- Validation rules run after before triggers — so values set in a before trigger are validated.
- An after trigger that updates the same object starts a new save cycle for those records (recursion risk).
- A workflow field update can make your update triggers fire twice in one transaction.
- Async work and emails only happen after commit — if the transaction rolls back, they never run.
Example
apex
trigger LeadTrigger on Lead (before insert) {
for (Lead l : Trigger.new) {
if (String.isBlank(l.LeadSource)) l.LeadSource = 'Web';
}
}
A validation rule ISBLANK(LeadSource) will not fire for these leads, because validation rules run after the before trigger filled the field.
Interview questions
- Do validation rules run before or after before-triggers? → After.
- Why might an update trigger run twice? → Workflow field update re-fires it (or recursion from an after trigger).
- When are emails from a trigger actually sent? → After commit.