Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
Salesforce Developer
medium

What's the order of execution within a trigger transaction?

When a record is saved, Apex runs in this order:

  1. System validation — required fields, max length, foreign keys.
  2. All `before` triggers fire (one trigger per object recommended; if multiple exist, ordering is undefined).
  3. Custom validation rules evaluate.
  4. Before-save flows run (record-triggered flows configured for fast field updates).
  5. Database commit-1 — record is saved but not yet committed.
  6. All `after` triggers fire. Record's Id is now populated.
  7. Assignment rules (Lead/Case).
  8. Auto-response rules (Lead/Case).
  9. After-save record-triggered flows.
  10. Workflow rules — legacy field updates and outbound messages.
  11. Process Builder processes.
  12. If a workflow field update happened, before/after triggers and validation rules fire AGAIN on those affected fields (re-entry).
  13. Escalation rules (Case).
  14. Roll-up summary recalculation.
  15. Sharing rules evaluation.
  16. Database commit-2 — transaction is now durable.
  17. Async logic@future, queueable, batch, outbound messages, platform events that publish on commit.

Implications for trigger code:

  • before triggers can mutate Trigger.new directly without DML.
  • after triggers run on records that are already in the DB but pre-commit.
  • Outbound messages, async Apex, and platform events fire only after commit-2 — they don't see intermediate state.
  • Recursion: if your trigger fires another DML on the same object, the trigger fires again — guard with a static recursion flag.

Why this answer works

Critical. The "workflow re-entry" point catches subtle bugs. The "async fires after commit-2" detail is what differentiates synchronous from async behaviour.

Follow-ups to expect

Related dictionary terms