In our test classes, we utilize testSetup methods that create and insert records in preparation for their use in the test methods of the class.

I found today that if I'm running tests in Production via the Developer Console, and deploying to Production via SublimeText / HaoIde, that the deployment fails because it is "UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: []" - seemingly because multiple tests are trying to use the testSetup records at the same time.

We have our Test Execution settings set to "Disable Parallel Apex Testing - Executes test methods one at a time", so in theory this shouldn't be happening, right? Why is Salesforce not executing these tests asynchronously?

  • Trick is that during deployment, tests are running in serial mode always. But very often even test are failing in serial mode. You can try post test code of methods which are failing, probably someone have seen similar issue – kurunve Jun 28 '16 at 19:37
  • I can think of a scenario where multiple asynchronous process are executed that uses same utility from tests and test.starttest() and test.stoptest() are not used properly. – Anurag Jun 28 '16 at 19:45

Your Answer

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

Browse other questions tagged or ask your own question.