Courseiva

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

A developer needs to write an Apex test class for a service that makes a callout to an external REST API. The test method must simulate the callout response without making an actual HTTP request. Which approach should the developer use?

⚠ Common exam trap

The trap here is thinking that `Test.startTest` or `@isTest(SeeAllData=true)` can handle callouts, when only `HttpCalloutMock` can simulate them.

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 use `Test.setMock` to register the mock before calling the service method.

The correct approach is to implement the `HttpCalloutMock` interface and register it with `Test.setMock`. This allows the test to simulate the external API response without making a real HTTP request. Other options do not provide a way to mock callouts; they either do not prevent the callout or are unrelated to mocking.

Answer analysis

Option-by-option breakdown

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

  • ✗

    Annotate the test method with `@isTest(SeeAllData=true)` to allow the callout to access external data.

    Why it's wrong here

    `@isTest(SeeAllData=true)` grants access to org data, not external callouts. It does not mock or allow callouts. Callouts in tests are not permitted unless mocked. The annotation is irrelevant to callout mocking and could expose the test to org data, which is not needed here.

  • ✗

    Replace the callout with a `@future` method and test the future method using `Test.stopTest` to force execution.

    Why it's wrong here

    `@future` methods are used for asynchronous processing, not for mocking callouts. While `Test.stopTest` forces asynchronous execution, the future method would still attempt a real callout unless mocked. This approach does not simulate the callout response and would still require `HttpCalloutMock` to avoid a callout exception.

  • ✓

    Implement the `HttpCalloutMock` interface and use `Test.setMock` to register the mock before calling the service method.

    Why this is correct

    `HttpCalloutMock` is the standard interface for mocking HTTP callouts in Apex tests. By implementing the `respond` method and registering the mock with `Test.setMock(HttpCalloutMock.class, mockInstance)`, the test can simulate the external response without making a real callout. This is the required approach for testing callouts in Apex.

  • ✗

    Use `Test.startTest` and `Test.stopTest` to isolate the callout and prevent it from executing during the test.

    Why it's wrong here

    `Test.startTest` and `Test.stopTest` are used to reset governor limits and execute asynchronous code, not to prevent callouts. They do not mock callouts. Without a mock, a callout in a test method would cause a `CalloutException`. The developer must use `HttpCalloutMock` to simulate the callout.

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.