Tags

,

Suppose, we want to access Standard Pricebook Id in the test class and this can be achieved in 2 ways:

a. Annotate the test class with @isTest(SeeAllData=true).
b. Use getStandardPricebookId() method of Test Class as given below.

Id pricebookId = Test.getStandardPricebookId();// This is available irrespective of the state of SeeAllData.

Imagine we have a test class which creates a record in Custom object and once the record is saved, flow is called which creates Pricebook/Product/Pricebook entry records. In this case, we would have to go with annotating the test class with SeeAllData=true as we do not need to pass Standard Pricebook Id instead it is queried inside the flow, but it will be visible only with SeeAllData=true.

Please let me know for any comments/clarification.

Advertisements