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
Asked
Active
Viewed 556 times
1 Answers
3
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!
Anup
- 3,810
- 6
- 26
- 41
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
– suresh Jul 14 '14 at 13:20