function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
maiyakumaiyaku 

Constructor not defined in Test Class

Class is use override view record. I can open but Test Class not work ! 

 

public class genMembershipConditionsPDF{

    public genMembershipConditionsPDF(ApexPages.StandardController controller) {
             gotoPDFPage();
    }
    
   
    public Pagereference gotoPDFPage()
        {
            return new Pagereference('/apex/MembershipConditionsPDF?Id='+Apexpages.Currentpage().getParameters().get('Id'));  
        }
}

 

@isTest
private class test_genMembershipConditionsPDF 
{
    static testMethod void myUnitTest() {
    
        Account Acc = new Account();
        Acc.name = 'Test';
        insert Acc;
         
        Membership_Conditions__c MC = new Membership_Conditions__c();
        MC.Copy_of_organisational_structure__c = True;
        MC.OrganizationsID__c = Acc.id;
        MC.Designation__c = 'Test';
        insert MC;
    
        ApexPages.StandardSetController controller = new ApexPages.StandardSetController(MC);
        genMembershipConditionsPDF sc = new genMembershipConditionsPDF();
        PageReference S = sc.gotoPDFPage();

    }
}

 

Thank you so much.

Best Answer chosen by Admin (Salesforce Developers) 
SurekaSureka

Hi,

 

Your test method should be:

 

ApexPages.StandardSetController controller = new ApexPages.StandardSetController(MC);
        genMembershipConditionsPDF sc = new genMembershipConditionsPDF(controller);

Also, as you are calling gotoPDFPage() method from constructor, you don't have to explicitly call.

 

Just a suggestion, instead of calling, gotoPDFPage() from the constructor, call the method from the <apex:page action="{!gotoPDFPage}"> for better performance.

 

Thanks

Sureka

 

All Answers

SurekaSureka

Hi,

 

Your test method should be:

 

ApexPages.StandardSetController controller = new ApexPages.StandardSetController(MC);
        genMembershipConditionsPDF sc = new genMembershipConditionsPDF(controller);

Also, as you are calling gotoPDFPage() method from constructor, you don't have to explicitly call.

 

Just a suggestion, instead of calling, gotoPDFPage() from the constructor, call the method from the <apex:page action="{!gotoPDFPage}"> for better performance.

 

Thanks

Sureka

 

This was selected as the best answer
maiyakumaiyaku

I'm Change but error 

 

Constructor not defined: [ApexPages.StandardSetController].<Constructor>(SOBJECT:Membership_Conditions__c)

 

Test Class : 

 

ApexPages.StandardSetController controller = new ApexPages.StandardSetController(MC);
        genMembershipConditionsPDF sc = new genMembershipConditionsPDF(controller);
        Pagereference S = sc.gotoPDFPage();

Page :

<apex:page standardController="Membership_Conditions__c" extensions="genMembershipConditionsPDF" >
    <apex:form >
       <apex:outputLink value="{!URLFOR($Action.Account.View,Membership_Conditions__c.OrganizationsID__c)}" id="theLink">« Back to List: Pages</apex:outputLink>
    <apex:pageBlock >
    <apex:pageblockButtons >
                <apex:commandButton id="printReport" value="Print Membership Conditions " action="{!gotoPDFPage}"/>
     </apex:pageblockButtons>

 

Thank you so much.

SurekaSureka

Hi,

 

Instead of "ApexPages.StandardSetController" use "ApexPages.StandardController"

 

 

ApexPages.StandardController controller = new ApexPages.StandardController(MC);
        genMembershipConditionsPDF sc = new genMembershipConditionsPDF(controller);
        Pagereference S = sc.gotoPDFPage();

 

Thanks

Sureka

 

maiyakumaiyaku

OK ! this work .

 

OMG i'm Sacatterained.

 

Thank you so much Sureka.