Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Extension Controller which gets back a different set of Opportunities based on the value of HTTP parameter named display sent in. So my code is as such:

public OpportunityListExtension(ApexPages.StandardSetController stdController) {
    // blank constructor

public List<Opportunity> getOpportunities() {
    PageReference pageRef = ApexPages.currentPage();
    String display = pageRef.getParameters().get('display');
    String whereclause = '';
    if (display == (LOST)) {
    } else if (display.equals(INACTIVE)) {

Based on the the value of display I return different Opportunities. Works great but I need a unit test for this and I am not sure how to pass in the display value to the controller.

Here is my test:

public static void testOpportunityListExtension() {
    PageReference pageRef = Page.Opportunities;
    // create an opp
    Opportunity opp = new Opportunity(name='testOpp');
    opp.stageName = 'Closed Won';
    opp.CloseDate = - 4;
    List<Opportunity> opps = new List<Opportunity>();
    insert opps;

    ApexPages.StandardSetController sc = 
             new ApexPages.StandardSetController(new Opportunity[]{});
    // ?????? Not sure how to pass in display value
    OpportunityListExtension ole = new OpportunityListExtension(sc);
    List<Opportunity> oppsFromController = ole.getOpportunities();        

    System.assertEquals(1, oppsFromController.size());
    Opportunity oppportunity = opps.get(0); 
share|improve this question
up vote 6 down vote accepted

The function getParameters() returns a Map<String, String> to which you can add items. In your test you can use something like this:

PageReference pageRef = Page.Opportunities;
pageRef.getParameters().put('display', 'INACTIVE');
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.