• About
  • Contact me!

Salesforce Everywhere

~ Blog on Salesforce Dev and admin stuff

Salesforce Everywhere

Category 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.

Advertisement

Blog Stats

  • 114,773 hits

Archives

Recent Posts: Salesforce Everywhere

How to get field values on onLoad in lightning-record-edit-form in LWC?

Using Dynamic Actions

How to check if the logged in user is a Guest user or not in APEX class?

How to Close Quick action in LWC

Lightning component to filter Products and display results in lightning data table

Connect with me

  • View @manibalan_s’s profile on Twitter
  • LinkedIn

Developer links

  • Salesforce Developer website
  • Salesforce Success Community

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

Website Powered by WordPress.com.

  • Follow Following
    • Salesforce Everywhere
    • Already have a WordPress.com account? Log in now.
    • Salesforce Everywhere
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar