+ Start a Discussion
Vj@88Vj@88 

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

Hi,

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?

Thanks,
Vijay
 
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.

Thanks,
Amit Chaudhary