0

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.

rjp
  • 151
  • 3

2 Answers2

0

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.

Neel Mota
  • 1
  • 1
  • Thanks for your reply, Neel. That's a different error you are pointing out though when a record is being updated in an after update or insert, https://www.google.com/search?q=salesforce+update+record+read+only, versus when a record is (row) locked. – rjp Jul 12 '23 at 13:25
0

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.
eyescream
  • 18,088
  • 2
  • 34
  • 46
  • Thank you for your reply, eyescream :). I think your last bullet point, updating several detail records in a master-detail relationship is the case, as also pointed out in the link I added in the question I posted. I guess I'm thinking in the same thread or transaction, the lock obtained of the same thread is re-entrant (https://stackoverflow.com/questions/1312259/what-is-the-re-entrant-lock-and-concept-in-general) in a database context. – rjp Jul 12 '23 at 13:31
  • Have you tried calling it with SELECT FOR UPDATE? Anything interesting in the debug log? I've written many triggers on "detail" that update something on "master" and they coexist with flows, workflows, rollup summary fields... Could be something weird in your setup, hard to say. "Should work" – eyescream Jul 12 '23 at 15:23