What is Row Lock issue in Salesforce?

What is Row Lock issue in Salesforce? 

In Salesforce, a row lock happens when two or more transactions try to update the same record at the same time. Salesforce locks the record to maintain data integrity, but if another transaction can’t get the lock, it fails with a row lock error. This usually happens when multiple child records update the same parent record, like many Opportunities updating one Account. To fix it, we reduce contention — by batching updates, using async jobs (Queueable/Batch), serial Bulk API, or consolidating updates so the parent is updated once instead of many times


Real-World Example of Row Lock Issue

*"Let’s say I have an Account with 1,000 Opportunities. Whenever an Opportunity is updated, we have a trigger that also updates the parent Account’s Total Revenue field.

Now imagine multiple sales reps are updating Opportunities under the same Account at the same time. Each transaction tries to update the same Account record. Salesforce locks that Account row while it’s being updated. If another transaction tries to update it before the lock is released, a row lock error occurs."*


🛠️ How I solved it:

  1. Instead of updating the Account in every Opportunity trigger, I used a Queueable job to batch the updates.

  2. Now, multiple Opportunity updates only create “update requests” in a Queue, and the Account gets updated once per batch instead of 1000 times.

  3. This reduced contention, and row lock errors disappeared.


👉 So the moral is:

  • Row locks happen when multiple child records try to update the same parent at once.

  • Solution is to decouple and consolidate those updates into async jobs or batches.

0 Comments

Post a Comment

Post a Comment (0)

Previous Post Next Post