I'm trying to write an apex test class for my apex (extension) of my visualforce page which display list of partners from partner__c sObject and do some actions on its rows like edit and delete. while writing my apex test class I got this error

Compile Error: Constructor not defined: [ApexPages.StandardController].(List)

My Apex class

public with sharing class partnersCtrl {
    private ApexPages.standardController stdController;
    public partner__c partnerObj{set;get;}
    public partner__c partnerObjDelete {set;get;}
     public string partnerId{set;get;} // Selected Partner Id for Edit.

    public partnersCtrl(ApexPages.StandardSetController controller) {
        this.stdController = stdController;

    public pageReference getPartner() {
        partnerObj = [SELECT Id,Name,Email__c FROM partner__c WHERE Id =: partnerId];
        return null;

    public PageReference savePartner() {
                upsert partnerObj;
                partnerObj = new partner__c();
        return null;

     public pageReference DeletePartner() {
         partnerObjDelete = [Select Id from partner__c where Id =: partnerId];
         delete partnerObjDelete ;

         return null;

VisualForce page (just part of it)

<apex:page standardController="Partner__c"

  <apex:form >
      <apex:pageBlock title="Partners List">

          <apex:pageBlockTable value="{!partners}" var="pt" id="mid">   
              <apex:column headerValue="Actions">
                  <apex:commandLink action="{!getPartner}"
                      <apex:param name="partnerId"
              <apex:column value="{!pt.Name}"/>
              <apex:column value="{!pt.Email__c}"/>

Apex test class

public class partnersCtrlTest {

    public static testMethod void testController() {

        partner__c p = new partner__c();

        Lead l = new Lead(firstname='test',email='[email protected]',
                          company = 'company', lead_type__c = 'Partner');
        insert l;
        p = [SELECT Id,name FROM partner__c where lead__c =: l.id];

        list<partner__c> partners = [SELECT Id,name FROM partner__c];

        ApexPages.PageReference myVfPage = Page.partners_list;
        ApexPages.StandardController sc = new ApexPages.StandardController(partners);
        partnersCtrl testCtrl = new partnersCtrl(sc);

        testCtrl.partnerId = p.Id;

  • you need to insert partner__c record.. why you are not inserting partner__c record? Also you are using standardSetController. then use same in test class
    – Ratan Paul
    Jan 25, 2016 at 11:56
  • Sorry I updated the question, when I insert a lead with type partner, I've a trigger will automatically create partner object. the partner related to lead @Ratan Jan 25, 2016 at 11:58
  • 1
    Okay Then Issue in your standardSetController.. Use standardSetController in test class instead ApexPages.StandardController
    – Ratan Paul
    Jan 25, 2016 at 12:00

1 Answer 1

ApexPages.StandardController sc = new ApexPages.StandardController(partners);

change this into

ApexPages.standardSetController sc = new ApexPages.standardSetController(partners);

It will solve your problem.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .