System.DmlException: Insert failed. First exception on row 0; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record, how to rectify kindly hep me
-
Can you share your code and the line numbers where you are getting the error?– Chetan GuptaJul 14, 2014 at 13:10
-
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: [] Stack Trace Class.UnhandledExceptionEmailService_TEST.severityLevelValue: line 51, column 1 Class.UnhandledExceptionEmailService_TEST.unhandledException: line 64, column 1– sureshJul 14, 2014 at 13:20
1 Answer
You get this error message when the record that you are updating is locked. To avoid this issue in a test class you should create your own test data inside your test class instead of relying on the data in the org. This is a best practice to avoid test failures in different sandboxes. Create or setup your data between Test.start() and Test.stop() before doing any validation or assertions.
Alternatively, there might be a batch job or data loader job updating records that you are trying to do dml on. Also a possibility but less like is lock contention due to account data skew.
hope this helps!