function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sandy CartographerSandy Cartographer 

Email to case fail: unable to obtain exclusive access to this record

About once in ten times, email to case fails for us with the error message:

The following errors were encountered while processing an incoming email:
 
UNABLE_TO_LOCK_ROW : unable to obtain exclusive access to this record


While I understand why this is happening, I can't seem to be able to find a way around it. Since the incoming email doesn't get stored anywhere when the insert fails, there is no way for me to attempt a reinsert using Apex. (We managed to implement that when new emails come to cases that are closed, as we can insert those emails to the same case and then use that to create a new case.)

Is there any workaround for this? We would really prefer it if we didn't get glaring errors in the email. Can a chatter post be implemented with the details of the incoming email? Any help would be appreciated. Thanks!
PratikPratik (Salesforce Developers) 
Here is the knowledge article:


Description
What does this error mean and why was the case not created?  "UNABLE_TO_LOCK_ROW : unable to obtain exclusive access to this record" 
Do I have to manually create the case now? 

Resolution
If a case is attempting to be created and another user in your organization is also working on a parent record then a lock could be placed within the database that will prevent updates to that record.  This is done to maintain data integrity.

For example, John, from ABC Inc., is attempting to log a case via Email-to-Case, but at the same time Dave (an employee within your organization) is making changes to the Account record for ABC Inc.  The ABC Inc. record is locked during this time and an error is generated referencing this lock and the case creation fails.  The case will need to be manually created at this point.

You can refer to:

https://help.salesforce.com/apex/HTViewSolution?urlname=Email-to-Case-error-UNABLE-TO-LOCK-ROW-unable-to-obtain-exclusive-access-to-this-record&language=en_US

Thanks,
Pratik

P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.
Sandy CartographerSandy Cartographer
Hi Pratik. Like I said, I already know *why* it is happening. My question was if there is a way to reinsert the case after it fails during the first insert.
PratikPratik (Salesforce Developers) 
Hi Sandy,

There is no perfect solution as this issue is regarding resource contention.

You can refer to this blog which has few workarounds.
http://kb.internetcreations.com/articles/Troubleshooting/UNABLE-TO-LOCK-ROW-unable-to-obtain-exclusive-access-to-this-record/?l=en_US&fs=RelatedArticle

Thanks,
Pratik
 
Sandy CartographerSandy Cartographer
Yes, Pratik, I had seen that blog post too. It's been a year, so I was curious if something new had come up or if someone had managed to implement it via triggers. Thanks!
PratikPratik (Salesforce Developers) 
Hi Sandy,

Unfortunately nothing yet. I will post here if i find any workaround or solution to this issue.

Thanks,
Pratik