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 UPDATE in short transactions deliberately
  • Retry using Database.update with error inspection, or re-enqueue via Queueable
  • Avoid unnecessary parent updates (update only when values change)
apex-triggertriggerrecord-lockingperformance