0

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"
           showHeader="false" 
           recordSetVar="partners" 
           extensions="partnersCtrl">

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

          <apex:pageBlockTable value="{!partners}" var="pt" id="mid">   
              <apex:column headerValue="Actions">
                  <apex:commandLink action="{!getPartner}"
                                    reRender="edit_form">
                      <span>Edit</span>
                      <apex:param name="partnerId"
                                  value="{!pt.id}"
                                  assignTo="{!partnerId}"/>
                  </apex:commandLink>
              </apex:column>
              <apex:column value="{!pt.Name}"/>
              <apex:column value="{!pt.Email__c}"/>
          </apex:pageBlockTable>
      </apex:pageBlock>
   </apex:form>
</apex:page>

Apex test class

@isTest
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];

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

        testCtrl.partnerId = p.Id;
        testCtrl.getPartner();
        testCtrl.savePartner();

        Test.stopTest();
    }
}
3
  • 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

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

change this into

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

It will solve your problem.

0

You must log in to answer this question.

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