SF-PD2 Advanced Developer Fundamentals Practice Question
A developer is writing a test method for a class that performs a SOQL query on a custom object. The test must ensure that the query returns the expected number of records. Which testing approach should be used to create test data that is isolated from the organization's data?
⚠ Common exam trap
The trap here is assuming that test methods automatically have access to sample data or that SeeAllData=true is a good practice, when in fact tests start with an empty database unless data is explicitly created.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Create test records within the test method using DML operations and then run the query.
Creating test records within the test method using DML ensures that the data is isolated and rolled back after the test. This allows the developer to control the dataset and verify the query returns the expected number of records without interference from existing organizational data.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use Test.loadData to load a static resource containing test records.
Why it's wrong here
Test.loadData is useful for loading large datasets from a static resource, but it still inserts records into the test context. While it provides isolation, it is more complex than needed for a simple query test. The developer could use it, but it is not the primary approach for creating isolated test data for a specific test scenario.
- ✗
Use @isTest(SeeAllData=true) to access existing records and avoid creating test data.
Why it's wrong here
Using SeeAllData=true allows the test to access real organizational data, but this is discouraged because it makes tests dependent on the org's state and can lead to unpredictable results. It does not provide isolation and may cause false positives or negatives due to existing records.
- ✓
Create test records within the test method using DML operations and then run the query.
Why this is correct
In Apex tests, data created within the test method is isolated to that test and rolled back after execution. By inserting test records and then querying them, the developer ensures the query returns exactly the expected records, independent of the org's data. This is the recommended approach for reliable unit tests.
- ✗
Annotate the test class with @isTest and rely on the default data that Salesforce provides in test contexts.
Why it's wrong here
Salesforce does not provide default data in test contexts; the test context starts with no data unless SeeAllData is true or data is created. Relying on default data would result in queries returning no records, failing the test. The developer must explicitly create test data.
About these practice questions
This SF-PD2 question is part of Courseiva's 226-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Salesforce exam blueprint
This SF-PD2 practice question is part of Courseiva's free Salesforce certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the SF-PD2 exam.