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
Gaurav GulanjkarGaurav Gulanjkar 

Constructor not defined in test class

I am deploying a controller and a test class to production. I am getting an error while deploying the code as 

line 38, column 57: Constructor not defined: [BulkTaskController.cEngineeringChangeTask].<Constructor>(Required_Task__c)

cEngineeringChangeTask is a wrapper class whoes constructor takes 2 parameters 1) object reference 2) string

                           
Vishal_GuptaVishal_Gupta
Hi Gaurav,

Can you please share your code.

Thanks,
Vishal
Arunkumar RArunkumar R
Hi Gaurav,

    While initializing class you need to pass the parameter in order to avoid issue. I would like to suggesst compile all class in sandbox and check out if there any issue.

    Ensure you have added wrapper class and depent class is added in change set.

   If the problem persist, please post your code here.
Gaurav GulanjkarGaurav Gulanjkar
Folowing is the test class

public class ClsChangeTaskControllerTest {
    
    public static testMethod void ChangeTaskControllerTest(){ 
        LL_Site__c testSite   = new LL_Site__c();
        testSite.Name = 'TestDemoSite1';  
        testSite.Site_Type__c = 'Thermal';
        insert testSite;
          
        Engineering_Change__c ec = new Engineering_Change__c();
        ec.Name = 'Test Request';
        ec.Site__c = testSite.Id;
        insert ec;
        
        Engineering_Change_Task__c e1 = new Engineering_Change_Task__c();
        e1.Engineering_Change_Request__c = ec.id;
        e1.Category__c = 'Design'; 
        e1.Required_Task2__c = 'Provide Temporary P&ID';
        e1.Task_Deadline__c = Date.today();
        insert e1;
        
        Task_Category__c t1 = new Task_Category__c();
        t1.Name = 'Testing Sample';
        t1.Type_Of_Category__c = 'Thermal';
        insert t1;
        
        Required_Task__c r1 = new Required_Task__c();
        r1.Name = 'Testing Dependent Sample';
        r1.Task_Category__c = t1.Id;
        r1.Type_of_Task__c = 'Thermal';
        r1.Task_Name__c = 'Testing Dependent Sample';
        insert r1;
        
        apexpages.currentpage().getparameters().put('Param1',ec.id);      
          ApexPages.StandardController sc = new ApexPages.StandardController(e1);
          BulkTaskController cpdf1 = new BulkTaskController(sc);
          
          BulkTaskController.cEngineeringChangeTask cew1 = new BulkTaskController.cEngineeringChangeTask(r1,'test');
          
          cpdf1.processSelected();
          cpdf1.getItems();
          cpdf1.searchValues = t1.Id;
          cpdf1.typeStringSet.add('Thermal');
          cpdf1.search();
          
    }
}
Vishal_GuptaVishal_Gupta
Hi Gaurav,

Its seems from your wrapper name that you need to pass Engineering_Change__c instance in your wraaper class, currently you are paasing 
Required_Task__c instance, please verify again. Its just my assumption, can confirm only checking after your class code.

Thanks,
Vishal

 
Vishal_GuptaVishal_Gupta
Hi Gaurav,

I found that you have two constructor in wrapper class and you are only using in which you are passing 2 parameters, please try to remove first constructor and try again with your test class.


public class cEngineeringChangeTask {

        public Required_Task__c con {get; set;}
        public Boolean selected {get; set;}
        public String comments {get; set;}
        //public cEngineeringChangeTask(){}
        
        public cEngineeringChangeTask(Required_Task__c c, String comments) {
            con = c;
            selected = false;
            this.comments = comments;
        }
    } 


Thanks,
Vishal 
Gaurav GulanjkarGaurav Gulanjkar
Thanks Vishal and Arunkumar,

Just changed the wrapper class as below and the controller got deployed:

public class cEngineeringChangeTask {

        public Required_Task__c con {get; set;}
        public Boolean selected {get; set;}
        public String comments {get; set;}
        public cEngineeringChangeTask(){}
        
        public cEngineeringChangeTask(Required_Task__c c) {
            con = c;
            selected = false;
        }
        
        public cEngineeringChangeTask(Required_Task__c c, String comments) {
            con = c;
            selected = false;
            this.comments = comments;
        }