# Transactions, the save order and recursion

*Platform Developer Study Guide · Process Automation and Logic · Last updated October 16, 2026 · https://www.certifyforce.com/study-guide/platform-developer/process-automation-and-logic/transactions-order-of-execution-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.

- Certification: Salesforce Platform Developer
- Exam section: Process Automation and Logic
- Study guide: https://www.certifyforce.com/study-guide/platform-developer

**Official exam objective:**

> Describe the relationship between Apex transactions, the save order of execution, and the potential for recursion and/or cascading.

## 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()` and `Database.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

| Fact | Detail | Source |
|---|---|---|
| Transaction failure | An error in any operation rolls back the entire transaction; nothing is committed | [Apex Transactions](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_transaction.htm) |
| When DML commits | Once, after roll-ups and criteria-based sharing, near the end of the save order | [Order of Execution](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm) |
| Before-save flow position | Immediately before Apex before triggers | [Before-Save Flows](https://help.salesforce.com/s/articleView?id=platform.flow_concepts_trigger_record.htm&type=5) |
| Custom validation rules | Run after before triggers, so they see values those triggers set | [Order of Execution](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm) |
| Modifying Trigger.new | Allowed only in before triggers; after-trigger records are read-only | [Trigger Context Variables](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_context_variables.htm), [Triggers](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers.htm) |
| Roll-up summary | Parent (and grandparent) records go through their own save procedure | [Order of Execution](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm) |
| Recursive save | Skips steps 9 (assignment rules) through 17 | [Order of Execution](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm) |
| Static variable scope | One transaction; persists across trigger invocations, reset for the next transaction | [Static and Instance Variables](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_static.htm) |
| Savepoint cost | Counts toward the DML statement limit | [Transaction Control](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_transaction_control.htm) |
| Rollback and statics | Static variables aren't reverted by a rollback | [Transaction Control](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_transaction_control.htm) |

## Check yourself

- 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?

## Sources

- [Triggers and Order of Execution](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm)
- [Apex Transactions](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_transaction.htm)
- [Transaction Control](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_transaction_control.htm)
- [Static and Instance Methods, Variables, and Initialization Code](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_static.htm)
- [Triggers](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers.htm)
- [Trigger Context Variables](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_context_variables.htm)
- [Bulk DML Exception Handling](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dml_bulk_exceptions.htm)
- [Before-Save Record-Triggered Flows](https://help.salesforce.com/s/articleView?id=platform.flow_concepts_trigger_record.htm&type=5)
- [How Flows Run in Transactions](https://help.salesforce.com/s/articleView?id=platform.flow_concepts_transaction.htm&type=5)

## About the full unit

The "Core concepts", "Exam traps" and "Worked scenario" sections of this unit and reading progress are included in the full study guide. The separate practice exams option includes the reviewed question bank and timed mock exams. The bundle includes both where available. See [current options and prices](https://www.certifyforce.com/pricing).
