1

We are running into problems with our unit tests which use the standard pricebook. When they are run separately they work fine, but as soon as we do a "run all" several tests fail with 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: 01s0Y000005PZuEQAW: []

We have been experimenting with the SeeAllData, but either with it on or off it will cause this error. As far as I can see we are not updating the pricebook itself, but we are setting it's Id on our quote / order line items. So maybe it is being updated because of references being added?

Anyone ran in a comparable issue or knows what might be causing this issue?

3

I bet you have enabled parallel test execution. A fast fix is to disable parallel test execution.

If you want to look deeper, when you set Id of this PriceBook2 to some quote / order line items and update/insert them, that causes to recalculate summary fields on PriceBook2. While you have parallel test execution, two or more tests are trying to gain access to this test Pricebook2 at same time.

There is a Locking Statements that locks the record via your custom SOQL query, hence you can't apply it to Pricebook2 in test and the only option for me is to disable parallel test execution.

| improve this answer | |
  • Sweet, that solved the problem! This option can be found in Setup -> Apex Test Execution -> Options – Stijn Dec 15 '17 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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