Courseiva

SF-PD2 Testing, Debugging, and Deployment Practice Question

A developer is writing an Apex test class for a controller that uses a Visualforce page with a standard controller. The test must cover pagination logic that relies on the StandardSetController. Which TWO actions should the developer take to ensure the test is reliable and covers the pagination behavior? (Choose two.)

⚠ Common exam trap

The trap here is assuming that isolating limits or bypassing queries simplifies pagination testing, when in fact pagination requires multiple pages of real data and a proper page context.

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

✓

Use Test.setCurrentPage() to set the Visualforce page context and then instantiate the StandardSetController with a query locator.

To reliably test pagination with StandardSetController, the test must create enough records to span multiple pages and then invoke the pagination methods. Additionally, setting the Visualforce page context with Test.setCurrentPage() and instantiating the StandardSetController with a query locator ensures the controller operates as it would in a real page. These two actions together exercise the pagination logic and verify the expected behavior across pages.

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 page size to a large number so that all test records fit on one page, simplifying the test and avoiding pagination complexities.

    Why it's wrong here

    Setting a large page size defeats the purpose of testing pagination because all records would appear on a single page, and next()/previous() would have no effect. Pagination logic only executes when there are multiple pages. This approach would not test the pagination behavior at all, leaving the logic untested and potentially buggy.

  • ✓

    Use Test.setCurrentPage() to set the Visualforce page context and then instantiate the StandardSetController with a query locator.

    Why this is correct

    StandardSetController is typically instantiated in a controller extension, and its behavior can depend on the Visualforce page context. Using Test.setCurrentPage() sets the page reference, and then the test can instantiate the StandardSetController with a query locator to simulate the controller's data set. This ensures the pagination methods operate on the expected data and page context, making the test more realistic and reliable.

  • ✗

    Use Test.startTest() and Test.stopTest() to isolate the pagination logic and reset governor limits between pages.

    Why it's wrong here

    Test.startTest() and Test.stopTest() are used to isolate governor limits for a specific block of code, but they do not reset limits between individual pagination method calls. Pagination methods like next() and previous() do not consume significant limits, and isolating them is not necessary. This action does not specifically contribute to covering pagination behavior and may not affect the test's reliability.

  • ✗

    Use Test.isRunningTest() in the controller to bypass the query and return a hardcoded list of records for pagination testing.

    Why it's wrong here

    Bypassing the query with Test.isRunningTest() would prevent the test from exercising the actual StandardSetController and its pagination logic. The test would validate a fake data set, not the real behavior. This anti-pattern reduces test effectiveness and can hide issues with the query or pagination. It does not ensure reliable coverage of the pagination behavior.

  • ✓

    Create test data that exceeds the page size to force multiple pages, and then invoke the pagination methods such as next() and previous().

    Why this is correct

    To test pagination, the test must have enough records to span more than one page. Creating data that exceeds the page size ensures that next() and previous() have multiple pages to navigate. Then, calling these methods and asserting the current page and records returned verifies the pagination logic. This approach directly exercises the StandardSetController's behavior and is essential for reliable coverage.

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.