i get an UNABLE_TO_LOCK_ROW error when running my tests in parallel. The error occurs when creating a pricebookentry for the standard pricebook. As far as i know Salesforce locks also the parent Object when inserting a object. Which would mean that in this case while inserting the pricebookentry the pricebook is locked. When now a parallel test wants to add another entry to the locked pricebook the test throws the UNABLE_TO_LOCK_ROW error.

When not running in parallel all the tests passes. But since the test suite is quite big i really would like to run them in parallel in order to save time.

Does anyone know how to get around this?

  • Is it while deploying or regular test run?
    – zokito
    Apr 23, 2015 at 12:10
  • it is happening in both situation. Apr 23, 2015 at 12:23
  • Could you please share some of you test? How do you use SeeAllData attribute?
    – Gres
    Apr 23, 2015 at 13:03

2 Answers 2


Place all of your tests that involve the Standard Price Book into a single class, and use @testSetup to create the products/price book entries you need. This way, the singular "test copy" of the Standard Price Book will only be locked once. You can place all of your other tests into separate classes. Tests do not run in parallel within a single class, so you'll avoid the row lock.


You need to Disable Parallel Apex Testing (Develop - Apex Test Execution - Options)

  • When not running in parallel everything works fine but i really would like to run them in parallel in order to save time. Apr 23, 2015 at 12:25
  • If you run them in parallel, you'll get this kind of error. What I would do, it's to create different records for each test. Apr 23, 2015 at 12:28
  • I'm using different pricebookentry records in the Tests. The Problem is that the standard pricebook is locked when adding pricebookentries. As far as i know it is not possible to add different standard pricebooks. Apr 23, 2015 at 12:44
  • Yes, you can not create another standard pricebook
    – Gres
    Apr 23, 2015 at 13:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .