Courseiva

SF-PD2 Process Automation, Logic, and Integration Practice Question

A developer must write a test method for an Apex service that performs an HTTP callout to a shipping-rate API. The test must not reach the external service and must assert that the service handles a successful response. Which approach is required?

⚠ Common exam trap

The trap here is assuming that wrapping callout code in Test.startTest and Test.stopTest makes the platform return a default successful response.

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, register it with Test.setMock, and inside the mock's respond method return an HttpResponse constructed with the desired status code and body.

Apex tests cannot perform real callouts, so the only way to exercise callout code is to register a mock through Test.setMock. The HttpCalloutMock implementation returns a fabricated HttpResponse, which makes the success path testable and repeatable while guaranteeing that no traffic reaches the shipping-rate API.

Answer analysis

Option-by-option breakdown

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

  • ✗

    Set the endpoint URL to a static resource path in the test and rely on the platform to serve the canned response from that resource.

    Why it's wrong here

    Static resources are not callout endpoints, and pointing an HttpRequest at a static resource path does not produce a valid HTTP response. The platform would still attempt an outbound callout or throw an exception, so the test cannot assert success behavior and no canned response is served automatically.

  • ✗

    Annotate the test method with @isTest(SeeAllData=true) so the test can reach the external service and receive real shipping rates, then assert on the returned values.

    Why it's wrong here

    SeeAllData only affects access to org data, not callout behavior, and real callouts are not permitted from test methods regardless of that annotation. Attempting a live callout throws System.CalloutException, so the test fails; relying on external data would also make the test non-deterministic and fragile.

  • ✓

    Implement the HttpCalloutMock interface, register it with Test.setMock, and inside the mock's respond method return an HttpResponse constructed with the desired status code and body.

    Why this is correct

    Test.setMock with an HttpCalloutMock implementation intercepts callouts made during the test, so no external request leaves the platform. The mock's respond method supplies a synthetic HttpResponse, letting the test assert the service's parsing and success-path behavior deterministically without depending on the live shipping API.

  • ✗

    Wrap the callout in Test.startTest and Test.stopTest; the framework automatically blocks outbound callouts during tests and returns a default 200 response.

    Why it's wrong here

    Test.startTest and Test.stopTest only delimit the code that receives a fresh set of governor limits; they do not intercept or block callouts. Without a registered mock, a callout in a test throws a System.CalloutException, so this approach fails rather than returning a default 200 response.

About these practice questions

One of 226 original SF-PD2 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.