Courseiva

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

A developer is writing a complex asynchronous batch Apex job that processes millions of financial transaction records. The job needs to maintain running totals across batches and update a summary logging record upon completion. Which mechanism allows state to be accurately preserved across individual executeBatch transactions?

⚠ Common exam trap

Candidates often confuse the 'Database.Stateful' interface with the 'Database.Batchable' interface, incorrectly assuming that standard class variables automatically persist across the distinct, isolated transaction chunks of a Batch Apex job.

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 Database.Stateful interface on the batch class definition to preserve instance member variable states across transaction chunks.

Implementing the Database.Stateful interface in a Batch Apex class ensures that instance member variables retain their values across distinct transaction chunks. Without this interface, member variables reset between execute method invocations. Preserving state is essential for maintaining running totals and aggregate metrics during large-scale data processing.

Answer analysis

Option-by-option breakdown

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

  • ✗

    Declare instance member variables inside the batch class without implementing any special interfaces.

    Why it's wrong here

    Instance variables reset between executeBatch transactions because each batch chunk runs in a fresh transaction, so running totals are lost. They are tempting because instance state works within a single synchronous execution, but Database.Stateful is required to persist member values across batch transactions.

  • ✓

    Implement the Database.Stateful interface on the batch class definition to preserve instance member variable states across transaction chunks.

    Why this is correct

    Database.Stateful preserves instance member variables between each executeBatch transaction, so running totals survive chunk boundaries. Without it, each batch reinitialises the class and accumulated values are lost, breaking the summary logging record update on completion.

  • ✗

    Store running totals inside static variables within the batch class, relying on the Apex transaction cache.

    Why it's wrong here

    Static variables reset between executeBatch transactions because each batch chunk runs in its own transaction context, so running totals are lost. They suit single-transaction reuse within one execution, not cross-batch state. Database.Stateful is required to carry instance variables across batches.

  • ✗

    Write running totals to a custom metadata type record inside each execute method iteration.

    Why it's wrong here

    Custom metadata records are cached and deployed as configuration; DML against them inside execute iterations is not supported for updating running totals, and each batch transaction would not reliably persist increments. Custom metadata suits deployable configuration, not mutable transactional state; Database.Stateful preserves totals instead.

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.