Courseiva

SF-PD2 Testing, Debugging, and Deployment Practice Question

A developer needs to deploy a new Apex class to production that makes a callout to an external REST service. The callout must be made from a trigger. During testing in a sandbox, the developer writes a test class that performs DML to insert a record that fires the trigger, but the test fails with a 'CalloutException: Methods defined as TestMethod do not support Web service callouts' error. What should the developer do to allow the test to execute the callout successfully?

⚠ Common exam trap

The trap here is assuming that Test.startTest() or SeeAllData=true can bypass the callout restriction, when actually only mocking the callout with HttpCalloutMock is permitted.

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(HttpCalloutMock.class, new MyCalloutMock()) before the DML operation.

The correct solution is to use HttpCalloutMock to simulate the external service. This allows the test to execute the callout logic without violating the platform's restriction on real callouts during tests. It also ensures that the test remains isolated, repeatable, and fast, which is essential for reliable continuous integration.

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 callouts.

    Why it's wrong here

    The @isTest(SeeAllData=true) annotation grants access to real organization data during tests, but it has no effect on the callout restriction. Tests are still prohibited from making actual web service callouts. Using SeeAllData=true can also lead to unreliable tests and is generally discouraged unless absolutely necessary.

  • ✓

    Implement the HttpCalloutMock interface and use Test.setMock(HttpCalloutMock.class, new MyCalloutMock()) before the DML operation.

    Why this is correct

    Implementing HttpCalloutMock and registering it with Test.setMock allows the test to simulate the external service's response without making an actual callout. This is the correct approach because it satisfies the test's callout requirement while avoiding the restriction against real web service callouts in tests. It also ensures consistent and fast test execution.

  • ✗

    Use Test.startTest() and Test.stopTest() around the DML operation to enable callouts.

    Why it's wrong here

    Test.startTest() and Test.stopTest() are used to isolate governor limits and execute asynchronous code, but they do not enable web service callouts in tests. The restriction against callouts in tests remains regardless of these methods. Therefore, this approach would not resolve the CalloutException.

  • ✗

    Wrap the callout in a try-catch block and ignore the CalloutException.

    Why it's wrong here

    Catching the exception would prevent the test from failing, but it would not test the callout logic at all. The test would pass without verifying that the callout is made or that the response is handled correctly. This approach defeats the purpose of testing and could hide real issues in production.

About these practice questions

Courseiva writes every SF-PD2 question from scratch — 226 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or 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.