# Consistent writes: transactions, locking and upsert keys

*Platform Data Architect Study Guide · Salesforce Data Management · Last updated October 26, 2026 · https://www.certifyforce.com/study-guide/platform-data-architect/salesforce-data-management/consistent-writes-transactions-locking-and-upsert-keys*

How the platform keeps writes consistent: transaction boundaries, savepoints and partial-success DML, FOR UPDATE locks, the save order of execution, post-commit work, External ID upserts, Composite allOrNone, mixed DML, formula fields and global value sets.

- Certification: Salesforce Platform Data Architect
- Exam section: Salesforce Data Management
- Study guide: https://www.certifyforce.com/study-guide/platform-data-architect

**Official exam objective:**

> Given a customer scenario, recommend techniques to ensure data is persisted in a consistent manner.

## What the exam expects

- Keep related writes all-or-nothing with savepoints, Database methods, Composite allOrNone and mixed-DML separation.
- Stop lost updates under concurrency with `FOR UPDATE`, and explain how its locks behave.
- Place a validation rule, flow, trigger or roll-up in the order of execution and predict what fails.
- Send notifications only after commit, and make integration retries idempotent with External ID + Unique upserts.
- Keep values consistent with formula fields, restricted picklists and global value sets.

Key terms: **transaction** (all DML in one request, committed or rolled back together); **savepoint** (a marked database state to roll back to); **partial success** (Database methods with `allOrNone` false); **External ID** (a field holding another system's key); **post-commit logic** (work that runs only after the commit).

## Key facts

| Fact | Detail | Source |
|---|---|---|
| Rollback to an earlier savepoint | Later savepoints become invalid; using one is a runtime error | [Transaction Control](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_transaction_control.htm) |
| Static variables | Not reverted by rollback or partial-success retries | [Transaction Control](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_transaction_control.htm), [Triggers and Order of Execution](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm) |
| Partial-success edges | An invalid value set by a before trigger stops the partial insert; SOAP retries unfailed records up to three times, then fails the call | [Bulk DML Exception Handling](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dml_bulk_exceptions.htm) |
| Locking query limits | No `ORDER BY`; a waiting client gives up after 10 seconds; callouts release locks | [Locking Statements](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_locking_statements.htm) |
| REST conditional update | `If-Unmodified-Since` returns 412 Precondition Failed if the record changed (ETag/If-Match: Account only) | [Conditional Request Headers](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_rest_conditional_requests.htm) |
| Composite request | Up to 25 subrequests in one API call | [Send Multiple Requests Using Composite](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_composite_composite_post.htm) |
| Database method default | `allOrNone` is true unless you pass false | [DML Statements vs. Database Class Methods](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_database.htm) |
| `FOR UPDATE` lock | Others can query, not update; released at transaction end | [Locking Statements](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_locking_statements.htm) |
| Multiple triggers, same event | Firing order isn't guaranteed | [Key Reminders](https://help.salesforce.com/s/articleView?id=000005694&language=en_US&type=1) |
| Upsert key matched twice | Error; record neither inserted nor updated | [Upserting Records](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_examples_upsert.htm) |

## Check yourself

- Why does a caught exception leave orphaned parent records?
- When should an integration mark its External ID field Unique too?
- Which field type keeps a parent's value current on millions of children without updates?

## Sources

- [Triggers and Order of Execution](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm)
- [Transaction Control](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_transaction_control.htm)
- [DML Statements vs. Database Class Methods](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_database.htm)
- [Bulk DML Exception Handling](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dml_bulk_exceptions.htm)
- [Conditional Request Headers](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_rest_conditional_requests.htm)
- [Locking Statements](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_locking_statements.htm)
- [Upserting Records](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_examples_upsert.htm)
- [Custom Field Attributes](https://help.salesforce.com/s/articleView?id=platform.custom_field_attributes.htm&language=en_US&type=5)
- [Process Order for Salesforce Automation Rules and Apex Triggers - Key Reminders](https://help.salesforce.com/s/articleView?id=000005694&language=en_US&type=1)
- [Platform Event Fields](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_define_ui.htm)
- [Composite Request Body](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/requests_composite.htm)
- [Send Multiple Requests Using Composite](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_composite_composite_post.htm)
- [sObjects That Can't Be Used Together in DML Operations](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dml_non_mix_sobjects.htm)
- [Create a Global Picklist Value Set](https://help.salesforce.com/s/articleView?id=platform.fields_creating_global_picklists.htm&language=en_US&type=5)
- [Validation Rules](https://help.salesforce.com/s/articleView?id=platform.fields_about_field_validation.htm&language=en_US&type=5)
- [General Guidelines for Data Loads](https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/asynch_api_planning_guidelines.htm)

## About the full unit

The "Core concepts", "Exam traps" and "Worked scenario" sections of this unit, its 20 linked practice questions, and unlimited timed mock exams are included with the Platform Data Architect pack (USD $19): https://www.certifyforce.com/practice-exams
