0

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 Gupta Jul 14 '14 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 – suresh Jul 14 '14 at 13:20
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.

https://developer.salesforce.com/blogs/engineering/2013/01/reducing-lock-contention-by-avoiding-account-data-skews.html

hope this helps!

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.