Skip to content

Test failure: unable to lock row

Detection

  • String: UNABLE_TO_LOCK_ROW
  • Applies to: Apex test failures

Examples

  • System.DmlException: Update failed. First exception on row 0 with id 001Aa000000AbCdEFG; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: []

Resolution

Another test or job updated the same record at the same time.
- Mark the test class with @isTest(isParallel=false), or disable parallel Apex testing in the target org (Setup -> Apex Test Execution -> Options)
- Create the test data in each test, instead of using existing records

Comments