You need to sign in to do that
Don't have an account?

System.DmlException: Insert failed. First exception on row 0; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record
Hi All,
I am getting this error while performing 'Run All Tests'. However, individual test classes works fine. This error is also intermittent. I am not sure how to fix this and why I'm getting this error. Can anyone help?
I can see probably where the problem might be as you said the Tests run fine when you run them inidividually. I'm assuming you got (SeeAllData=true) set for those test classes...if so - then I highly suggest to re-think if you really need visibility to the existing data....
Another alternative might be to use a Static variable in an Independed class and where you see there is a DML statement resulting in this error..set/change the value of static variable...On a side note - do remember that when you do DML on a sObject salesforce also locks the Parent Object relating to that record if there are any in Master-Detail relationship.
Hope it helps..
Thanks,
Mohammed
Hello Pooja,
Enable the property 'Disable Parallel Apex Testing'. This you can do by following
Setup->Develop->Apex Test execution ->Click on options button a window will be shown enable the property mentioned, and try running all tests again.
This will for sure sort your problem.
Thanks,
Sid
Running all the tests clsses sequentially helps me removing the error. However, I am facing a new issue when I deploy my change set. I get 'System.LimitException: Apex CPU time limit exceeded' error for all the methods of test classes. I am not sure how to deal with it.
Check if there are any update statements inside a for loop. If so then remove and try.
You may find of the best practice to write apex code: https://developer.salesforce.com/page/Apex_Code_Best_Practices