function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AntigoniAntigoni 

Test error: Standard price not defined

Hello there,

In an effort to try and utilize the new summer 14' changes, I am creating a test pricebook2 in my test class. I am including the code below:

      testProduct1 = FT_TestObjects.getCreateTestProduct();
      testPricebook1 = new Pricebook2(Name='Test Pricebook', IsActive=true);
      insert testPricebook1;
      testPricebook1 = [Select Id, Name From Pricebook2 Where Name =: 'Test Pricebook'];
     
      PricebookEntry standardPricebook = new PricebookEntry(Pricebook2Id=Test.getStandardPricebookId(), Product2Id=testProduct1.Id, UnitPrice=10.00, IsActive=true, UseStandardPrice=false);
      insert standardPricebook;

      testPricebookEntry = FT_TestObjects.getCreateTestPricebookEntry(testProduct1.id, testPricebook1.id);



So far all good. However when I try to do the same from another class, and run the two test classes at the same time I get an error message: "UNABLE_TO_LOCK_ROW" , exception thrown on the line I am inserting the standardPricebook.

If I comment out the lines where I am creating + inserting the standard pricebook I get the following error mesage: System.DmlException: Insert failed. First exception on row 0; first error: STANDARD_PRICE_NOT_DEFINED, No standard price defined for this product: []

Is there anyway that I can work around that, e.g. create a test standard pricebook2 ?




        
    
Vishant ShahVishant Shah
Hello,

I had the exact same error and after a lot of trial i created a dummy product in my test and production org to overcome the issue. and just did a soql on the product to create my test opps

Dont slack me for doing this, it used to work before summer 14 and started failing since, MY org has 120 classes and they all used to pass before, 40% failures since summer 14


Ta 
Vish
Pramod_SFDCPramod_SFDC
Hi,

Good Day,

UNABLE_TO_LOCK_ROW error is thrown in the below mentioned scenario.

If a case is attempting to be created and another user in your organization is also working on a parent record then a lock could be placed within the database
that will prevent updates to that record.  This is done to maintain data integrity.

For example, John, from ABC Inc., is attempting to log a case via Email-to-Case, but at the same time Dave (an employee within your organization) is making changes
to the Account record for ABC Inc.  The ABC Inc. record is locked during this time and an error is generated referencing this lock and the case creation fails. 
The case will need to be manually created at this point.

For the Other Exception " System.DmlException: "
This means that there is a required field in parent Object to the particular object that is created by you and that is not being populated.

This might help you resolve the issue you arer facing


Regards
Pramod_-SFDC