Transactions, the save order and recursion
How an Apex transaction commits or rolls back as one unit, where before-save flows, triggers and validation rules sit in the save order of execution, how DML and roll-up summaries cascade into more saves, and how savepoints and transaction-scoped static variables control rollback and recursion.
Describe the relationship between Apex transactions, the save order of execution, and the potential for recursion and/or cascading.
~8 min read · 9 practice questions ·
What the exam expects
- Predict what survives an unhandled exception in an Apex transaction.
- Place before-save flows, triggers, validation rules, roll-ups and the commit in the save order, and predict what a validation rule sees.
- Recognise cascading: DML, flows and roll-up summaries that send another record through its own save.
- Diagnose trigger recursion and choose the fix: move same-record updates before the save, or guard re-entry with a static variable.
- Use
Database.setSavepoint()andDatabase.rollback(), and know their limits.
Key terms: transaction (operations that commit or roll back together); save order of execution (the fixed sequence Salesforce runs on insert, update or upsert); cascading (one save starting another record's save); recursion (automation re-firing because of its own DML); savepoint (a point you can roll the database back to).
Key facts
- Detail
- An error in any operation rolls back the entire transaction; nothing is committed
- Detail
- Once, after roll-ups and criteria-based sharing, near the end of the save order
- Detail
- Immediately before Apex before triggers
- Detail
- Run after before triggers, so they see values those triggers set
- Detail
- Allowed only in before triggers; after-trigger records are read-only
- Detail
- Parent (and grandparent) records go through their own save procedure
- Detail
- Skips steps 9 (assignment rules) through 17
- Detail
- One transaction; persists across trigger invocations, reset for the next transaction
- Detail
- Counts toward the DML statement limit
- Detail
- Static variables aren't reverted by a rollback
Sources for this section (7)
- Apex Transactionsdeveloper.salesforce.com (opens in a new tab)
- Order of Executiondeveloper.salesforce.com (opens in a new tab)
- Before-Save Flowshelp.salesforce.com (opens in a new tab)
- Trigger Context Variablesdeveloper.salesforce.com (opens in a new tab)
- Triggersdeveloper.salesforce.com (opens in a new tab)
- Static and Instance Variablesdeveloper.salesforce.com (opens in a new tab)
- Transaction Controldeveloper.salesforce.com (opens in a new tab)
- Why does a value set on Trigger.new in a before insert trigger need no DML statement?
- When does inserting a detail record fire triggers on its master?
- Why does a static Boolean in a helper class stop trigger recursion when an instance variable does not?
- Which savepoint becomes invalid when you roll back to SP1 after creating SP1 and then SP2?
The questions are free to read. Answers with their sources and self-grading are included with the pack.
Keep reading with the Platform Developer pack
- Core concepts
- Exam traps
- Worked scenario
The pack includes:
- All 21 lessons of the Platform Developer guide, with reading progress
- Interactive decision walks and step-by-step sequence steppers
- Inline practice questions and one-click topic practice (9 questions for this lesson)
- An official source cited for every claim
- An AI tutor that answers from the guide
- Unlimited timed practice exams