I am trying to do an upsert using Database.Upsert() and getting this error:

"caused by: System.DmlException: Upsert failed. First exception on row 200; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record or 13 records:"

Normally, the code works fine, but on occasion I get the above error.

I know in SOQL statements you can use "FOR UPDATE", but I am doing Database.Upsert(). Is there anything that can be done to solve for this error?

  • Does salesforce.stackexchange.com/questions/20921/… answer your question? Commented Oct 27, 2020 at 18:47
  • No @SachinHooda - That suggests using "FOR UPDATE" in the SOQL statement as I mentioned in my comment. I am using Database.Upsert() and upserting a <List> of records. Commented Oct 27, 2020 at 22:59
  • My question is not a duplicate as it relates specifically to doing an UPSERT versus using a SOQL query Commented Oct 28, 2020 at 19:08


Browse other questions tagged .