In Salesforce, how does a row lock error happen when there's only a single transaction (thread) executing?

580 views Asked by At

When a user 'action' (in a general sense) is executed in Salesforce, assuming no callouts or async jobs are executed, isn't the code running in a single thread/transaction? Assuming so, how is it that I get a row lock error when I know I'm the only user in my personal sandbox (no other user is awaiting for the same record I'm updating). Based on this link: https://help.salesforce.com/s/articleView?id=000387767&type=1, it's possible to get a row lock error if there are thousands of child records. However, it does mention again if there are multiple users.

I ended up queueing the part of the code that was throwing the row lock error and the issue went away. However, I'm still confused per my query above.

2

There are 2 answers

1
Neel Mota On

Can you specify the transaction mode (after insert, after update) ? Also if possible can you specify which flow, apex class , etc throwing the error? If it’s “after update” it might possible that you are trying to update value of record which is already in “trigger”.

Let me summarise for you. We can not update record in after update.

4
eyescream On

You may have other operations updating same record

  • scheduled batch (background) jobs
  • side effects of an edit you did couple seconds ago that are still running (Queueable, @future etc, also background)
  • if you've just started a big recalculation operation (sharing rules recalc, converting from lookup to master-detail) system will typically be slower until email about completion comes.
  • if you're updating a detail in master-detail - it locks the parent. I think it's more prominent when there are rollup summary fields. And then if in the trigger of the detail you want to do your own update of parent - occassionally locking can kick in.