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
Dinesh123Dinesh123 

Running All test classes together

Hi I am facing a issue when I run all test cases together I am getting some error like unable to lock the row and those test classes are failing. However when I run then alone or single then they pass. Will this be a problem when we deploy to prod if all dont pass togehter? If so can some one guide how to overcome this scenario?
Best Answer chosen by Dinesh123
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

Please check below two more post for more detail:-
https://help.salesforce.com/apex/HTViewSolution?urlname=How-can-I-avoid-getting-lock-errors-in-my-organization-1327109108393&language=en_US (https://help.salesforce.com/apex/HTViewSolution?urlname=How-can-I-avoid-getting-lock-errors-in-my-organization-1327109108393&language=en_US)
https://developer.salesforce.com/blogs/engineering/2013/01/reducing-lock-contention-by-avoiding-account-data-skews.html

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

All Answers

Vj@88Vj@88
Hi,

I am getting the same error in our sandbox. let me know if you found the solution.

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

Please check below two more post for more detail:-
https://help.salesforce.com/apex/HTViewSolution?urlname=How-can-I-avoid-getting-lock-errors-in-my-organization-1327109108393&language=en_US (https://help.salesforce.com/apex/HTViewSolution?urlname=How-can-I-avoid-getting-lock-errors-in-my-organization-1327109108393&language=en_US)
https://developer.salesforce.com/blogs/engineering/2013/01/reducing-lock-contention-by-avoiding-account-data-skews.html

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
This was selected as the best answer
Dinesh123Dinesh123
Thanks Amit this is helpful