Courseiva

SF-PD2 Testing, Debugging, and Deployment Practice Question

A developer is preparing an Apex test class that must cover a service which schedules a Queueable job, and the test must verify that the queued job's logic actually ran and updated a record. The developer also needs the test to pass reliably in a CI pipeline. (Choose two.)

⚠ Common exam trap

The trap here is believing that enqueuing a Queueable job is enough, or that its execution can be detected through exceptions, rather than forcing execution with Test.stopTest() and asserting on resulting data.

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

✓

Assert on the updated record after Test.stopTest() returns, since the queued job's DML completes by then.

To test Queueable logic, enqueue the job between Test.startTest() and Test.stopTest(); stopTest() forces the asynchronous transaction to complete synchronously, and assertions placed afterward validate the real record changes. This pattern produces deterministic results in CI because the job's effects are observable before the test ends.

Answer analysis

Option-by-option breakdown

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

  • ✗

    Use Test.setCreatedDate() to backdate the queued job's enqueue timestamp so the scheduler picks it up immediately.

    Why it's wrong here

    Test.setCreatedDate() only overrides the CreatedDate field on sObjects inserted during the test; it has no effect on asynchronous job scheduling. Queueable jobs in a test run when stopTest() is invoked, not based on timestamps. Relying on this method would not cause the job to execute and would not help the assertions pass.

  • ✓

    Assert on the updated record after Test.stopTest() returns, since the queued job's DML completes by then.

    Why this is correct

    Once Test.stopTest() returns, all asynchronous transactions spawned during the test have finished, so the database reflects the DML the Queueable job performed. Querying and asserting on the record at that point validates the job's real behavior. This makes the test deterministic and meaningful rather than merely checking that the job was enqueued.

  • ✗

    Enqueue the job before Test.startTest() so it is queued outside the limit-reset boundary and runs independently.

    Why it's wrong here

    Asynchronous work enqueued before Test.startTest() is not guaranteed to execute when stopTest() is called, because stopTest only flushes work queued within its block. Enqueuing outside the boundary makes the test flaky and can leave the job unexecuted. The correct pattern is to enqueue inside the startTest/stopTest block so the job is captured and run.

  • ✗

    Wrap the enqueue call in a try/catch for System.AsyncException and treat a caught exception as proof the job executed successfully.

    Why it's wrong here

    System.AsyncException signals that a limit such as the queueable enqueue cap was exceeded, not that the job ran successfully. Catching it and treating it as success would mask real failures and produce a false positive. The job's actual effects must be verified through record state after stopTest(), not through exception handling around the enqueue call.

  • ✓

    Call Test.stopTest() after enqueuing the job so the platform executes the queued job synchronously before assertions run.

    Why this is correct

    Test.stopTest() forces all asynchronous work enqueued during the test, including Queueable, Future, and Batchable jobs, to execute before control returns. Placing assertions after stopTest() lets the test observe the record updates performed by the queued job. Without it, the job would never run in the test context and the assertions would fail or be meaningless.

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.