I have an inbound interface in my Salesforce org, it updates existing account records. The inbound interface being called by number of third party systems. Whenever two different requests try to same account record ending up with error-

UNABLE_TO_LOCK_ROW: unable to obtain exclusive access to this record.

How can overcome this issue, please help me. Is there any configurable setting available in Salesforce to enable multi theading? Or do we have any machanism to control or handle inbound requests?

  • Please include relevant sections of the interface code and settings. See How to Ask and take the tour to get the best out of SFSE and hopefully get the answer to your question.
    – Dave Humm
    Jul 18 '18 at 8:50

You need to be using FOR UPDATE in your SOQL, for all of the integrations that are encountering row locking errors, when you query these Accounts.

The problem is actually that you're already running multi-threaded: you have a synchronization/resource contention issue, which is a classic multi-threading problem in all parallel programming environments.

Using FOR UPDATE will establish a lock for the duration of the transaction, which will serialize access to the individual records and avoid the row locking error (a DmlException). Other clients attempting to lock the same records will wait up to 10 seconds for the lock to be released before they can proceed.

You need to be aware, since you're already experiencing synchronization problems, that any lock established by FOR UPDATE that is held for too long can result in another lock attempt timing out and throwing a QueryException. Tune your integrations for short transaction times as much as possible to avoid creating that issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.