Activity Forums Salesforce® Discussions Can I create Standard PriceBook From TestClass?

  • Radhakrishna

    Member
    April 18, 2017 at 8:10 am

    Hello Suraj,

    You can create price book entries for standard and custom price books in Apex tests.

    Previously, you couldn’t create price book entries in an Apex test by default unless the test had access to organization data via the @isTest(SeeAllData=true) annotation. With this new support, you can isolate your price book test data from your organization data. Note that custom price books can be created but standard price books cannot.
    Support for test price book entries is added for all tests, including tests that use the default data isolation mode (tests that can’t access organization data). With this support, you can do the following.

    Query for the ID of the standard price book in your organization with the Test.getStandardPricebookId() method.
    Create test price book entries with standard prices by using the standard price book ID that’s returned by Test.getStandardPricebookId().
    Create test custom price books, which enables you to add price book entries with custom prices.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos