How to get Standard Price Book Id in Salesforce Test Class?

How to get Standard Price Book Id in Salesforce Test Class?

Test.getStandardPricebookId() is used to get or fetch Standard Price Book Id in the Apex test class.

Sample Code:

Id pricebookId = Test.getStandardPricebookId();

Sample Apex Test Class:

@isTest
private class ProductTestClass {
    
    static testMethod void testPriceBook() {
        
        Id pricebookId = Test.getStandardPricebookId();
        Assert.isNotNull( pricebookId );
        
    }

}

Leave a Reply