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

Getting 'Unable to LOCK Row' error when executing all test classes at once


I am getting 'Unable to Lock Row' Exception(When inserting mock data)  when executing all test classes at once.
But if I execute the test classes one at a time, test classes are passing without any exception.
Can anyone please explain why?

Amit Chaudhary 8Amit Chaudhary 8
ROW_LOCK issue is very common if you have multiple users updating the record at the same time .Or say a batch job is running and is updating a record and same record another trigger or code snippet (usually a future method) is updating.
Account [] accts = [SELECT Id FROM Account LIMIT 2 FOR UPDATE];
Using FOR UPDATE keyword helps to achieve a lock a client end to prevent this locking issues .Here is a small article on sharing model to avoid this granular locking

On Apex Test Execution page click options and tick Disable Parallel Apex Testing. Then the testing will take longer but you won't get error

User-added image

Please let us know if this will help you.

Amit Chaudhary