Courseiva

SF-PD2 Testing, Debugging, and Deployment Practice Question

A developer is writing an Apex test class for a service that must be resilient against partial failures. The service calls a REST endpoint using a callout and, when the callout succeeds, performs a DML update on a set of Account records. The developer wants the test to simulate the HTTP response without hitting the real external system. Which approach should the developer use?

⚠ Common exam trap

The trap here is assuming Test.startTest() and Test.stopTest() somehow intercept or simulate web service callouts, when they only reset limits and flush asynchronous work.

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

✓

Implement the HttpCalloutMock interface and register it with Test.setMock(HttpCalloutMock.class, new MyMock()) before the callout is invoked.

The Apex testing framework provides Test.setMock with an HttpCalloutMock implementation precisely so callouts can be exercised without external dependencies. Registering the mock before the request executes makes the runtime substitute the developer-defined HttpResponse, letting assertions validate both the request built by the code and the handling of the response, including error status codes.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    Create the mock response by inserting a ContentVersion record and reference it from the callout using the endpoint URL of the mock.

    Why it's wrong here

    ContentVersion stores files and documents; it has no role in stubbing HTTP responses for Apex callouts. There is no platform mechanism that maps a ContentVersion to an outbound HttpRequest, so the callout would still attempt a real network transaction and fail inside the test context. This confuses file storage features with the callout mocking framework.

  • ✓

    Implement the HttpCalloutMock interface and register it with Test.setMock(HttpCalloutMock.class, new MyMock()) before the callout is invoked.

    Why this is correct

    Registering a mock that implements HttpCalloutMock through Test.setMock causes the Apex runtime to return the canned HttpResponse instead of performing a real HTTP transaction, so the test never touches the external service and remains deterministic. This is the supported mechanism for isolating callout logic in Apex tests and works regardless of whether the code under test uses Http or HttpRequest directly.

  • ✗

    Annotate the test method with @IsTest(SeeAllData=true) so the test can reach the live endpoint and then assert on the returned payload.

    Why it's wrong here

    SeeAllData=true only controls record visibility for queries; it does not permit callouts from a test context. Tests are still blocked from making real HTTP requests, so the request fails before any payload can be asserted. Relying on live data also makes the test non-deterministic and dependent on external system availability, which is exactly what the scenario wants to avoid.

  • ✗

    Wrap the callout in Test.startTest() and Test.stopTest() so the platform automatically intercepts the outbound request and returns a synthetic 200 response.

    Why it's wrong here

    Test.startTest() and Test.stopTest() only delimit the block where governor limits are reset and asynchronous work is forced to complete; they do not intercept HTTP traffic at all. Using them around a callout without a registered mock still produces the 'Methods defined as TestMethod do not support Web service callouts' failure, so this approach cannot simulate a response.

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 →

How Courseiva writes practice questions · Editorial policy

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.