SalesforceSalesforce
PDI · Question #137
PDI Question #137: Real Exam Question with Answer & Explanation
The correct answer is C: Use Test.getStandardPricebookid ( ) to get the standard price book ID.. To access the ID of the standard price book within a test class in Salesforce, developers should utilize the Test.getStandardPricebookId() method.
Submitted by anna_se· Apr 18, 2026Testing, Debugging, and Deployment
Question
A developer wants to get access to the standard price book in the org while writing a test class that covers an OpportunityLineItem trigger. Which method allows access to the price book?
Options
- AUse Test.loadData ( )and a static resource to load a standard price book
- BUse @TestVisible to allow the test method to see the standard price book.
- CUse Test.getStandardPricebookid ( ) to get the standard price book ID.
- DUse @IsTest (SeeAllData=True) and delete the existing standard price book
Explanation
To access the ID of the standard price book within a test class in Salesforce, developers should utilize the Test.getStandardPricebookId() method.
Common mistakes.
- A. While
Test.loadData()can load data from static resources, it is not used to access standard Salesforce setup data like the standard price book ID directly. - B.
@TestVisibleis used to allow test methods to access private or protected members of a class, not to retrieve standard Salesforce IDs like the standard price book ID. - D.
@IsTest(SeeAllData=True)exposes all org data, but it is generally discouraged, and deleting the standard price book is not a valid or safe approach to accessing its ID in a test.
Concept tested. Apex testing standard price book
Topics
#Apex Testing#Test Data Setup#Standard Price Book#System.Test Class
Community Discussion
No community discussion yet for this question.