SF-PD2 Advanced Developer Fundamentals Practice Question
When designing a unit test for a class that makes callouts, which pattern is the industry standard for ensuring the test does not actually send requests?
⚠ Common exam trap
Candidates often assume they can use standard mock callout classes without implementing the specific HttpCalloutMock interface, leading to runtime exceptions during unit tests.
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
✓
Using the System.Test.setMock() method with an implementation of HttpCalloutMock.
The HttpCalloutMock interface is the standard way to handle external requests in tests. Since Apex unit tests are prohibited from making actual network calls, implementing this interface allows developers to define a static response. This pattern is essential for creating deterministic tests that verify how code handles both success and failure scenarios without requiring an external service to be active or reachable.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Adding the @IsTest(SeeAllData=true) annotation to the test method.
Why it's wrong here
The SeeAllData annotation should be avoided because it compromises the isolation of unit tests. It does not prevent callouts from occurring, and relying on real data creates brittle tests that can fail due to external changes, violating the core principle that unit tests must be self-contained and repeatable.
- ✓
Using the System.Test.setMock() method with an implementation of HttpCalloutMock.
Why this is correct
System.Test.setMock is the officially supported mechanism for intercepting HTTP requests during unit testing. By passing an instance of a class that implements the HttpCalloutMock interface, the developer instructs the Apex runtime to return a predefined HttpResponse object instead of initiating an actual network request to the endpoint.
- ✗
Wrapping the callout code in a try-catch block to bypass execution.
Why it's wrong here
Wrapping a callout in a catch block does not prevent the callout from attempting to trigger. The runtime will still try to execute the network request before the catch block can handle any potential error, which leads to a runtime exception stating that callouts are not allowed in tests.
- ✗
Configuring a Remote Site Setting for the test domain.
Why it's wrong here
Remote Site Settings are necessary for production callouts, but they do not influence test behavior. Configuring them does not exempt the test from the restriction that real network activity is forbidden. The developer must still use a mock implementation to satisfy the platform's runtime constraints during the execution.
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.