nerdexam
Salesforce

PDI · Question #13

A developer needs to have records with specific field values in order to test a new Apex class. What should the developer do to ensure the data is available to the test?

The correct answer is B. Use Test.loadDataO < > and reference a CSV file in a static resource. To provide specific test data for an Apex class, a developer should use Test.loadData() to load records from a CSV file stored in a static resource.

Submitted by thandi_sa· Apr 18, 2026Testing, Debugging, and Deployment

Question

A developer needs to have records with specific field values in order to test a new Apex class. What should the developer do to ensure the data is available to the test?

Options

  • AUse Anonymous Apex to create the required data.
  • BUse Test.loadDataO < > and reference a CSV file in a static resource.
  • CUse SOQL to query the org for the required data.
  • DUse Test.loadDataO and reference a JSON file in Documents.

How the community answered

(30 responses)
  • A
    7% (2)
  • B
    80% (24)
  • C
    10% (3)
  • D
    3% (1)

Why each option

To provide specific test data for an Apex class, a developer should use `Test.loadData()` to load records from a CSV file stored in a static resource.

AUse Anonymous Apex to create the required data.

Anonymous Apex is typically used for one-off code execution and debugging, not for providing reusable, deterministic test data for Apex test classes.

BUse Test.loadDataO < > and reference a CSV file in a static resource.Correct

`Test.loadData()` is the recommended method to efficiently load large sets of structured test data into Apex test methods, enabling developers to define specific field values in a CSV file referenced from a static resource.

CUse SOQL to query the org for the required data.

Relying on existing org data via SOQL queries in test methods is an anti-pattern because it makes tests non-deterministic and prone to failure in different environments.

DUse Test.loadDataO and reference a JSON file in Documents.

`Test.loadData()` is designed to work exclusively with CSV files, not JSON files, and these files must be stored as static resources, not in the Documents folder.

Concept tested: Apex test data setup with Test.loadData()

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

Topics

#Apex Testing#Test Data Management#Test.loadData#Static Resources

Community Discussion

No community discussion yet for this question.

Full PDI Practice