+ Start a Discussion
Saurabh Gupta 3137Saurabh Gupta 3137 

UNABLE_TO_LOCK_ROW error while running all apex test classes


I am facing one issue during Run All Test in Sandbox on which I need some help
When i do run all test in sandbox then i face UNABLE_TO_LOCK_ROW error messages in some test classes

System.DmlException: Insert failed. First exception on row 0; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: []

As a solution i have disabled Parallel testing in sandbox which resolve the issue in sandbox  but want to know will  I face any issue during sandbox to production deployment ?
If yes , the how can the issue be resolved.
Pankaj GangpariaPankaj Gangparia

perform dml in system.runAs user in test class
Dear Saurabh,

When you deploy your code to production, you won't get this error because test classes will run synchronous in production.

The following link will may help you. https://developer.salesforce.com/forums?id=906F00000008qyTIAQ

Anjith kumar