An integration creating records in Salesforce keeps failing with 'UNABLE_TO_LOCK_ROW'. What's happening and how do you fix it?
Your confidence:Not rated
Model answer
What it means: two transactions tried to update (or lock) the same record at the same time, and one waited too long. Common causes:
- Parallel batches inserting children of the same parent (for example contacts under one account), which locks the parent.
- Data skew: thousands of records under one account or owned by one user, so many operations contend for it.
- Triggers or rollups updating a shared parent record on every child insert.
- Long transactions holding locks.
Fixes
- Sort the data by parent so the same parent's children land in the same batch; use serial mode for the worst cases.
- Reduce skew: spread children across parent records, avoid "catch-all" accounts and single integration-owner records (assign owners sensibly).
- Shorten transactions and move non-essential parent updates async.
- Retry with back-off in the integration for transient lock errors.
โ Key points to hit
โ Red-flag answers
- Just increasing retries forever
- Ignoring the data model cause
โช Follow-ups
What's ownership skew?
When one user owns a very large number of records (often over 10,000) of one object, sharing recalculations and some operations become slow and lock-prone. Distribute ownership or use a user who isn't in the role hierarchy โ verify current guidance.
Can lookup fields cause locking?
Yes. Inserting or updating a child locks the parent in some cases, especially master-detail and rollup summary relationships. Lookup skew (many children on one parent) amplifies it.