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
Surender reddy SalukutiSurender reddy Salukuti 

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

Hi Every one,

when i am executing test class i am geeting the error like below can any one help me . 

Error message 
System.DmlException: Insert failed. First exception on row 0; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record or 1 records: 
ShirishaShirisha (Salesforce Developers) 
Hi Surender,

Greetings!

When the same test class is being edited by any other user while you are trying to run the test class then this error occurs.So,I would suggest you to try again later or check if any other user is trying to modify at the same time to avoid error.

Reference:https://www.infallibletechie.com/2020/04/unabletolockrow-unable-to-obtain.html

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
SUCHARITA MONDALSUCHARITA MONDAL

Hi Surender,

Your record is getting processed from multiple classes/jobs. Try to create you own test records for corresponding test class.
 

Hope this helps!
Thanks,
Sucharita