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
jwolfjwolf 

Testing PricebookEntries in Version 24

With the latest update to the API in version 24, the default view of data in tests is to not be able to see all data, without explicitly using an annotation. Obviously that's good for testing practices, but it definitely gets in the way of how Salesforce does not allow for the creation of standard pricebooks.

 

The use case is as follows:

 

When creating pricebook entries for a custom pricebook, a standard entry for each custom entry must be created first.

In order to create a standard entry, we would need to find a standard pricebook.

Since we can't see all data, we can never retrieve the standard pricebook that exists in the org, nor can we just create a new standard pricebook to use.

 

Has anyone found a way around this without using the SeeAllData annotation?

carlocarlo

I have never used any test or written any code to deal with pricebooks.

 

How I deal with testing now without all data annotation is I specifically create the records I need.  So cant you create the standard price book records within your test?

jwolfjwolf

No, you cannot create the standard pricebook. Pricebook has an IsStandard flag which you cannot set.