• About
  • Contact me!

Salesforce Everywhere

~ Blog on Salesforce Dev and admin stuff

Salesforce Everywhere

Tag Archives: APEX Test Class

Tip#6: Standard Pricebook record visibility in Test Class

08 Tuesday Sep 2015

Posted by Mani in Apex, APEX Test class

≈ Leave a comment

Tags

APEX Test Class, Standard Pricebook

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.

Blog Stats

  • 146,218 hits

Archives

Cannot load blog information at this time.

Connect with me

  • View @manibalan_s’s profile on Twitter
  • LinkedIn

Follow this Blog via Email

Enter your email address and click on Follow us (below) to follow this blog and receive notifications of new posts by email.

Powered by WordPress.com.

 

Loading Comments...