nerdexam
Salesforce

PDI · Question #137

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?

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

How the community answered

(63 responses)
  • A
    2% (1)
  • B
    6% (4)
  • C
    89% (56)
  • D
    3% (2)

Why each option

To access the ID of the standard price book within a test class in Salesforce, developers should utilize the `Test.getStandardPricebookId()` method.

AUse Test.loadData ( )and a static resource to load a standard price book

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.

BUse @TestVisible to allow the test method to see the standard price book.

`@TestVisible` is 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.

CUse Test.getStandardPricebookid ( ) to get the standard price book ID.Correct

The `Test.getStandardPricebookId()` method is specifically designed to retrieve the ID of the standard price book in a test context, making it the most direct and reliable approach.

DUse @IsTest (SeeAllData=True) and delete the existing standard price book

`@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

Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_test.htm#apex_System_Test_getStandardPricebookId

Topics

#Apex Testing#Test Data Setup#Standard Price Book#System.Test Class

Community Discussion

No community discussion yet for this question.

Full PDI Practice