You need to sign in to do that
Don't have an account?
Parsa Motamedi
unable to obtain exclusive access to this record or 1 records: 07H7Y000000Cc1RUAS - when running tests
I'm getting a peculiar error, something I haven't seen before, when I run test classes. All the failing tests were passing successfully earlier (a week ago).
I get this error on some test classes where I refer to some Content- object. If I run these tests individually, some of them pass while some won't even pass if run them on their own.
I have one Library, which is the standard Assets Library. The error happens when I call insert on a list of ContentVersion records. I'm running these tests as System Administrator on our sandbox org.
How would I go about debugging this error?
Thanks in advance.
System.DmlException: Insert failed. First exception on row 0; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record or 1 records: 07H7Y000000Cc1RUAS: []The 07H prefix refers to ContentFolder.
I get this error on some test classes where I refer to some Content- object. If I run these tests individually, some of them pass while some won't even pass if run them on their own.
I have one Library, which is the standard Assets Library. The error happens when I call insert on a list of ContentVersion records. I'm running these tests as System Administrator on our sandbox org.
How would I go about debugging this error?
Thanks in advance.
Salesforce platform has a feature ROW LEVEL Security. This feature ensures that sharing and visibility set by salesforce administrators for the records have to be maintained. As a part of this feature, there are sharing calculations that the platform has to perform when the record ownership is changed or child records are created/modified.
A record can also go into a Locked State if it is a parent and part of master-detail relationships and child records are getting saved/updated.
You can read how apex can prevent such locks using the link here (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_locking_records.htm).
Using FOR UPDATE keyword in SOQL helps to achieve a lock on a client end to prevent these locking issues.
Account [] accts = [SELECT Id FROM Account LIMIT 2 FOR UPDATE];
Here are some helpful articles on how to design your sharing model to avoid granular locking
https://help.salesforce.com/apex/HTViewSolution?urlname=How-can-I-avoid-getting-lock-errors-in-my-organization-1327109108393&language=en_US
http://blogs.developerforce.com/engineering/2013/01/reducing-lock-contention-by-avoiding-account-data-skews.html
You can prevent using the below techniques
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.
This is not something that requires edits to the Apex code to fix. As I've mentioned, these tests were passing last week. There has been a change elsewhere that is causing this. I need help to narrow down where to look to fix this error.