Newer Version Available
Record-Level Locking
The locks are held very briefly and don’t present the same performance risks as some of the other organization locks. However, they can still cause updates to fail, so you must still be careful not to run updates to the same collections of records in multiple threads.
In addition to taking this standard precaution, developers and administrators should know that for objects with a master-detail relationship, when you update child records, the system locks the parent and the child records to prevent inconsistencies. For example, updating a child record whose parent has just been deleted in another thread. When objects being processed have a master-detail relationship, two situations in particular pose a risk of producing locking errors.
- Updates to parent records and their children are being processed simultaneously in separate threads.
- Updates to child records that have the same parent records are being processed simultaneously in separate threads.
Because Salesforce holds these locks very briefly, customers who experience a small number of locking errors might be able to handle the problem by adding retry logic to their integration code. If you experience frequent locking from integrations and mass updates, sequence batches so that the same records aren’t updated in multiple threads simultaneously.