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
KruzKruz 

Constructor not defined: [ApexPages.StandardController].<Constructor>()

Hello,
Please help me out to solve 'Constructor not defined: [ApexPages.StandardController].<Constructor>()' error while writing test class.

Original Apex Class:
public class MassAcknowlgement {
    public List<CGR__RulesStudio__c> RuleList {get;set;}
   // private ApexPages.StandardSetController standardController;
    private Set<Id> accIds = new Set<Id>();
    public MassAcknowlgement(ApexPages.StandardSetController standardController)
    {
       // this.standardController = standardController;
        RuleList = new List<CGR__RulesStudio__c>();
        for(CGR__RulesStudio__c accs : (List<CGR__RulesStudio__c>)standardController.getSelected()){
            accIds.add(accs.Id);
        }
        RuleList = [Select Id, Name,CGR__Rule_Description__c from CGR__RulesStudio__c WHERE ID IN :accIds];
    }
    public void ListAck(){
        List<CGR__Rule_Acknowledgement__c> ruleAck = new List<CGR__Rule_Acknowledgement__c>();
        for(CGR__RulesStudio__c a : RuleList){
            CGR__Rule_Acknowledgement__c ruleAc = new CGR__Rule_Acknowledgement__c();
            //  ruleAc.Name =a.Name;
            ruleAC.CGR__Rule_Description__c = a.CGR__Rule_Description__c;
            ruleAc.CGR__Rule_Name__c = a.Id;
            ruleAck.add(ruleAc);
        }
        insert ruleAck;
    }
}

Test Class:
 
@isTest
public class MassAcknowledgement_Test {
    static testMethod void MassAck(){
        test.startTest();
        RulesStudio__c rule = new RulesStudio__c ();
        ApexPages.StandardController sc = new ApexPages.StandardController (rule);
        MassAcknowlgement ma= new MassAcknowlgement(sc);
        ma.RuleList = new List<RulesStudio__c>();
        ma.ListAck();
        test.startTest();
    }
    
}

Thanks,
Kruz Soni
Best Answer chosen by Kruz
Raj VakatiRaj Vakati
Well .. try below
@isTest
public class MassAcknowledgement_Test {
    static testMethod void MassAck(){
        test.startTest();
        
        
        CGR__RulesStudio__c rule = new CGR__RulesStudio__c ();
        insert rule ; 
        
   Test.setCurrentPage(Page.aaaaaaaaa);
        ApexPages.StandardSetController setCon = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Id, Name FROM CGR__RulesStudio__c LIMIT 2]));
setCon.setSelected([SELECT Id, Name FROM CGR__RulesStudio__c LIMIT 2]);
     //   ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(rule);
        MassAcknowlgement ext = new MassAcknowlgement (setCon);
        
		ext.ListAck();
		
		
        test.startTest();
    }
    
}

code
 

 

All Answers

Raj VakatiRaj Vakati
@isTest
public class MassAcknowledgement_Test {
    static testMethod void MassAck(){
        test.startTest();
		
		
        RulesStudio__c rule = new RulesStudio__c ();
        insert rule ; 
		
   Test.setCurrentPage(Page.YOUR_PAGE);
  ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(rule);
  MassAcknowlgement ext = new MassAcknowlgement(stdSetController);
		
        test.startTest();
    }
    
}

Modify the StandardSetController from StandardController
KruzKruz
Hi Raj,

Thanks for the reply but still I get the same error. please review the below test class and suggest me to how it will achieve 100% code coverage.
 
@isTest
public class MassAcknowledgement_Test {
    static testMethod void MassAck(){
        test.startTest();
        
        
        RulesStudio__c rule = new RulesStudio__c ();
        insert rule ; 
        
   Test.setCurrentPage(Page.MassAcknowlgement);
  ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(rule);
  MassAcknowlgement ext = new MassAcknowlgement (stdSetController);
        
        test.startTest();
    }
    
}

Thanks,
Raj VakatiRaj Vakati
Can you share the visual force page and controller?
KruzKruz
Yeah Sure,

Apex Controller:
 
public class MassAcknowlgement {
    public List<CGR__RulesStudio__c> RuleList {get;set;}
    private ApexPages.StandardSetController standardController;
    private Set<Id> accIds = new Set<Id>();
    public MassAcknowlgement(ApexPages.StandardSetController standardController)
    {
        this.standardController = standardController;
        RuleList = new List<CGR__RulesStudio__c>();
        for(CGR__RulesStudio__c accs : (List<CGR__RulesStudio__c>)standardController.getSelected()){
            accIds.add(accs.Id);
        }
        RuleList = [Select Id, Name,CGR__Rule_Description__c from CGR__RulesStudio__c WHERE ID IN :accIds];
    }
    public void ListAck(){
        List<CGR__Rule_Acknowledgement__c> ruleAck = new List<CGR__Rule_Acknowledgement__c>();
        for(CGR__RulesStudio__c a : RuleList){
            CGR__Rule_Acknowledgement__c ruleAc = new CGR__Rule_Acknowledgement__c();
            //  ruleAc.Name =a.Name;
            ruleAC.CGR__Rule_Description__c = a.CGR__Rule_Description__c;
            ruleAc.CGR__Rule_Name__c = a.Id;
            ruleAck.add(ruleAc);
        }
        insert ruleAck;
    }
}

Visualforce Page:
 
<apex:page standardController="RulesStudio__c" extensions="MassAcknowlgement" recordSetVar="SelectedRec" action="{!ListAck}">
    <p>Record Created Successfully</p>
</apex:page>

 
Raj VakatiRaj Vakati
Use the below code
 
@isTest
public class MassAcknowledgement_Test {
    static testMethod void MassAck(){
        test.startTest();
        
        
        RulesStudio__c rule = new RulesStudio__c ();
        insert rule ; 
        
   Test.setCurrentPage(Page.aaaaaaaaa);
        ApexPages.StandardSetController setCon = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Id, Name FROM RulesStudio__c LIMIT 2]));

     //   ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(rule);
        MassAcknowlgement ext = new MassAcknowlgement (setCon);
        
		
		
		
        test.startTest();
    }
    
}

 
KruzKruz
Thank you, Raj!
Your code helps me to cover 68% code coverage
Raj VakatiRaj Vakati
Use this code for more coverage
 
@isTest
public class MassAcknowledgement_Test {
    static testMethod void MassAck(){
        test.startTest();
        
        
        RulesStudio__c rule = new RulesStudio__c ();
        insert rule ; 
        
   Test.setCurrentPage(Page.aaaaaaaaa);
        ApexPages.StandardSetController setCon = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Id, Name FROM RulesStudio__c LIMIT 2]));

     //   ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(rule);
        MassAcknowlgement ext = new MassAcknowlgement (setCon);
        
		ext.ListAck();
		
		
        test.startTest();
    }
    
}

 
KruzKruz
Hey,

In test class, I have already used 'ext.ListAck();' with the help that method code coverage is gone upto 68% but 'FOR Loop' in controller is not coverd yet. do you have any idea about it. I tried to insert acknowledgement record but it not worked.

Thanks.
Raj VakatiRaj Vakati
Insert "CGR__RulesStudio__c" records into the test class 


CGR__RulesStudio__c obj = new CGR__RulesStudio__c();
obj.name='test';
insert obj;
Raj VakatiRaj Vakati
@isTest
public class MassAcknowledgement_Test {
    static testMethod void MassAck(){
        test.startTest();
        
        
        CGR__RulesStudio__c rule = new CGR__RulesStudio__c ();
        insert rule ; 
        
   Test.setCurrentPage(Page.aaaaaaaaa);
        ApexPages.StandardSetController setCon = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Id, Name FROM CGR__RulesStudio__c LIMIT 2]));

     //   ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(rule);
        MassAcknowlgement ext = new MassAcknowlgement (setCon);
        
		ext.ListAck();
		
		
        test.startTest();
    }
    
}

 
KruzKruz
I have tried but still not increasing code coverage. still get 68% code coverage.
Raj VakatiRaj Vakati
Well .. try below
@isTest
public class MassAcknowledgement_Test {
    static testMethod void MassAck(){
        test.startTest();
        
        
        CGR__RulesStudio__c rule = new CGR__RulesStudio__c ();
        insert rule ; 
        
   Test.setCurrentPage(Page.aaaaaaaaa);
        ApexPages.StandardSetController setCon = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Id, Name FROM CGR__RulesStudio__c LIMIT 2]));
setCon.setSelected([SELECT Id, Name FROM CGR__RulesStudio__c LIMIT 2]);
     //   ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(rule);
        MassAcknowlgement ext = new MassAcknowlgement (setCon);
        
		ext.ListAck();
		
		
        test.startTest();
    }
    
}

code
 

 
This was selected as the best answer
KruzKruz
Thanks, Raj!

It will help me to cover 75%.
Raj VakatiRaj Vakati
That's great! Close this thread!
KruzKruz
Thanks for help i have got 100% code coverage.