nerdexam
Salesforce

PDI · Question #22

A developer has a single custom controller class that works with a Visualforce Wizard to support creating and editing multiple subjects. The wizard accepts data from user inputs across multiple…

The correct answer is B. Test.setCurrentPage(pageRef); D. ApexPages.CurrentPage().getParameters().put('input\', 'TestValue'); E. String nextPage -controller.save().getUrl(). To effectively test a Visualforce custom controller in a unit test, developers must simulate the page context, set URL parameters, and verify navigation outcomes.

Submitted by eva_at· Apr 18, 2026Testing, Debugging, and Deployment

Question

A developer has a single custom controller class that works with a Visualforce Wizard to support creating and editing multiple subjects. The wizard accepts data from user inputs across multiple Visualforce pages and from a parameter on the initial URL. Which three statements are useful inside the unit test to effectively test the custom controller? Choose 3 answers

Options

  • Ainsert pageRef.
  • BTest.setCurrentPage(pageRef);
  • Cpublic ExtendedController(ApexPages StandardController cntrl) { }
  • DApexPages.CurrentPage().getParameters().put('input', 'TestValue');
  • EString nextPage -controller.save().getUrl();

How the community answered

(23 responses)
  • A
    17% (4)
  • B
    74% (17)
  • C
    9% (2)

Why each option

To effectively test a Visualforce custom controller in a unit test, developers must simulate the page context, set URL parameters, and verify navigation outcomes.

Ainsert pageRef.

`insert pageRef` is syntactically incorrect; `pageRef` is an `ApexPages.PageReference` object used for page navigation or context, not an SObject that can be inserted into the database.

BTest.setCurrentPage(pageRef);Correct

`Test.setCurrentPage(pageRef)` is essential for simulating the Visualforce page context within a unit test, allowing the custom controller to properly interact with page-related methods and variables.

Cpublic ExtendedController(ApexPages StandardController cntrl) { }

`public ExtendedController(ApexPages.StandardController cntrl)` is a constructor signature for an extension controller, not a standalone custom controller, and is not a statement used *inside* a unit test to set up testing context.

DApexPages.CurrentPage().getParameters().put('input\', 'TestValue');Correct

`ApexPages.CurrentPage().getParameters().put('input', 'TestValue')` allows a unit test to programmatically set URL query string parameters, mimicking how a custom controller would receive input from the initial URL.

EString nextPage -controller.save().getUrl();Correct

`String nextPage = controller.save().getUrl()` is used to capture the `PageReference` returned by controller action methods, enabling the unit test to verify that the controller navigates to the expected page after an action.

Concept tested: Testing Visualforce Custom Controllers

Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_pages_testing.htm

Topics

#Apex Testing#Visualforce Controllers#URL Parameters#PageReference

Community Discussion

No community discussion yet for this question.

Full PDI Practice