A developer wants to get access to the standard price book in the org while writing a test class that covers an OpportunitylLineltem trigger.
Which method allows access to the price book?
Options:
A.
Use @IaTest (SeeAllData=true) and delete the existing standard price book,
B.
Use Test.loadData() and a static resource to load a standard price book,
C.
Use @TestVisible to allow the test method to see the standard price book.
D.
Use Teat.getStandardPricebookId() to get the standard price book 1D.
Answer:
D
Explanation:
Option D:Use Test.getStandardPricebookId() to get the standard price book ID.
Correct Answer.
Explanation:
The Test.getStandardPricebookId() method returns the ID of the standard price book, which can be used in test classes without using SeeAllData=true.
This allows the test to access and use the standard price book in a controlled manner.
[Reference:, Accessing the Standard Price Book in Tests, Option A: Use @IsTest(SeeAllData=true) and delete the existing standard price book., Not Best Practice and Risky., Explanation:, Using SeeAllData=true is discouraged as it can make tests dependent on org data., Deleting data in tests can have unintended consequences., Option B: Use Test.loadData() and a static resource to load a standard price book., Unnecessary., Explanation:, There's no need to load a standard price book via Test.loadData() when Test.getStandardPricebookId() is available., Option C: Use @TestVisible to allow the test method to see the standard price book., Incorrect Use of @TestVisible., Explanation:, @TestVisible is used to expose private members to test classes, not to access data., Conclusion:, The developer should use Test.getStandardPricebookId() to get the standard price book ID, which is Option D., ]