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?
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?
To access the standard price book in a test class, the correct method to use is Test.getStandardPricebookId(). This method is specifically designed to obtain the standard price book ID in a testing context, which is essential for covering an OpportunityLineItem trigger. The other options either involve incorrect approaches or methods not related to accessing the standard price book.
the Right answer
It is A because Test.getStandardPriceBookid() has to be used for this purpose only.
why not B ?
B is not correct, it specifically states "and DELETE the existing standard price book", which is not part of the question. On the other hand, A is correct
use the @isTest(SeeAllData=true) annotation to grant test classes and individual test methods access to all data in the organization
B is not correct, it specifically states "and DELETE the existing standard price book", which is not part of the question. On the other hand, A is correct
It is A because Test.getStandardPriceBookid() has to be used for this purpose only. Event id it is possible to use @isTest(SeeAllData=true) to access real data from a test Class, it is possible to read the Standard Price Book or to delete it anyway.
C THE RIGHT ONE
A because the test class has a method with the same name https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_test.htm#apex_System_Test_getStandardPricebookId
A is correct