nerdexam
SalesforceSalesforce

PDI · Question #13

PDI Question #13: Real Exam Question with Answer & Explanation

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.

Explanation

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.

Common mistakes.

  • A. Anonymous Apex is typically used for one-off code execution and debugging, not for providing reusable, deterministic test data for Apex test classes.
  • C. 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.
  • D. 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()

Reference. 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 PracticeBrowse All PDI Questions