Development questions
How do you handle UNABLE_TO_LOCK_ROW errors triggered during high-volume updates on parent records?
UNABLE_TO_LOCK_ROW occurs when concurrent transactions try to update the same record (often a parent that is locked by child inserts/roll-ups).
Mitigations:
- Reduce parallelism: use serial mode in Bulk API, smaller batch sizes
- Sort data by parent Id so transactions lock rows in the same order
- Avoid data skew (more than ~10,000 children under one parent)
- Use
FOR UPDATEin short transactions deliberately - Retry using
Database.updatewith error inspection, or re-enqueue via Queueable - Avoid unnecessary parent updates (update only when values change)
apex-triggertriggerrecord-lockingperformance
More Development questions
- What is an Apex Trigger in Salesforce and when should you use it over Flows?
- What is the difference between before triggers and after triggers?
- Explain all Trigger context variables (isInsert, isUpdate, isDelete, isUndelete, isBefore, isAfter, isExecuting, size, operationType).
- What is the difference between Trigger.new and Trigger.old?
- In which trigger events are Trigger.new and Trigger.newMap available?
- In which trigger events are Trigger.old and Trigger.oldMap available?