I am trying to write a test class for a StandardSetController with a very simple extension that processes a list of records that were selected from a related list. I am coming up short on how to get this to work and would love your input.

Visualforce Page: [JobReporting_MassReject.vfp]

<apex:page standardController="TR1__Job_Reporting__c" showHeader="false" sidebar="false" recordSetVar="records" extensions="JobReporting_RejectExt">
    <apex:form >    
        <apex:messages />
        <apex:pageBlock >
            <apex:pageMessages id="JobReportingRejectMessages"/>
            <apex:pageBlockTable value="{!selected}" var="jr">
                <apex:column value="{!jr.TR1__Contact__c}"/>
                <apex:column headerValue="Reject?" value="{!jr.TR1__isRejected__c}"/>
                <apex:column headerValue="Rejection Reason">
                    <apex:inputField value="{!jr.TR1__Rejection_Notification__c}" required="true"/>
                <apex:column headerValue="Rejection Notes">
                    <apex:inputField value="{!jr.TR1__Rejection_Notes__c}" style="width: 400px; height: 100px"/>
            <apex:pageBlockButtons >            
                <apex:commandButton value="Confirm" action="{!save}"/>
                <apex:commandbutton value="Cancel" action="{!cancel}"/>

Extension Class:[JobReporting_RejectExt.apxc]

public with sharing class JobReporting_RejectExt{
    ApexPages.StandardSetController setCon;
    public JobReporting_RejectExt(ApexPages.StandardSetController controller){
        setCon = controller;
        FOR (TR1__Job_Reporting__c jr:(TR1__Job_Reporting__c[])setCon.getSelected()){
            jr.TR1__isRejected__c = 'Yes';

Test Class:[JobReporting_RejectExt_Test.apxc]

private class JobReporting_RejectExt_Test {
    public static testMethod void TestReject(){

        TR1__Job_Reporting__c jrTest = new TR1__Job_Reporting__c();

        PageReference pageRef = Page.JobReporting_MassReject;

        **ApexPages.StandardSetController stdJR = new ApexPages.StandardSetController(jrTest);**
        JobReporting_RejectExt jr_ext = new JobReporting_RejectExt(stdJR);


Error message (Line 9 of Test Class):

"Constructor not defined: [ApexPages.StandardSetController].(TR1__Job_Reporting__c)"


The StandardSetController class has two constructors, one accepts a list of sobjects and the other accepts a query locator. There is no constructor which accepts just a single record which is why you are getting the error above.

TR1__Job_Reporting__c jrTest = new TR1__Job_Reporting__c();

// create a list
List<TR1__Job_Reporting__c> yourList = new List<TR1__Job_Reporting__c>();
// add your record(s) to this list

PageReference pageRef = Page.JobReporting_MassReject;

// change the constructor parameter to the list of objects
ApexPages.StandardSetController stdJR = new ApexPages.StandardSetController(yourList);
  • Thank you, Mark! This is exactly what I needed to get this test class to work. – John Mark Hulsey Aug 16 '17 at 22:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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