We currently have a batchprocess running from a managed package which runs every day for almost the whole day to update records of an object. When a user tries to do an update on this object we have a trigger which does an after update on this object we get the error:

first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record or 1 records:

As far as I have read this is caused by records being locked by the batch proces. One solution would be to add FOR UPDATE in the soql but since this is a managed package this is no option.

What would the solution be? Since I suppose that only the current batch gets locked, can this be resolved by passing the update from the trigger to a future class or should this be resolved in a different way?

Thanks in advance


I found a possible solution:


This method also accepts List, SObject, or List.

What I do not understand is how to use this. The return value is a map with Ids and Boolean values if locked or not.



Do I loop trough the map until the list is unlocked and then?:

update listToUpdate;


  • The record where this fails has 5 childrecords
  • I tried with future but this throws an error since the batch is also future
  • 1
    if the package allows the scope size to be reduced from 200 to a smaller value, you might have less frequent locks; deferring to an async means you need to build a retry mechanism
    – cropredy
    Jan 20, 2022 at 23:10
  • I suspect that this problem indicates you also have significant data skew. Is there an exceptionally large volume of child records associated with one or a very small number of parents?
    – David Reed
    Jan 21, 2022 at 5:53
  • @DavidReed The record which threw this error has 5 child records. Can this be an issue?
    – Thomas
    Jan 21, 2022 at 6:02

1 Answer 1


Since the batchprocess running from the managed package was causing our trigger to fail. I ended up removing the updates from the trigger and adding to a batch proces running every half an hour which seemed to resolve the issue.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .