Salesforce Platform Developer I (legacy) — Question 101
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?
Answer options
- A. Use Test.getStandardPricebookId() to get the standard price book ID.
- B. Use @IsTest(SeeAllData=true) and delete the existing standard price book.
- C. Use Test.loadData() and a Static Resource to load a standard price book.
- D. Use @TestVisible to allow the test method to see the standard price book.
Correct answer: A
Explanation
The correct answer is A because Test.getStandardPricebookId() is specifically designed to retrieve the ID of the standard price book in test contexts. Options B and C are incorrect as they either manipulate data inappropriately or do not directly provide access to the standard price book. Option D is also incorrect since @TestVisible does not grant access to data that is not otherwise visible in the test context.