+ Start a Discussion
bittubittu 

Constructor not defined: [wrappercls.InnerClassWrapper].<Constructor>(Boolean, SOBJECT:Contact)

How to over come this error:

 

Save error: Constructor not defined: [wrappercls.InnerClassWrapper].<Constructor>(Boolean, SOBJECT:Contact)at line 10 column 22

 

public with sharing class wrappercls {
    
    public InnerClassWrapper objICW {get;set;}
    public list<InnerClassWrapper> lstw {get; set;}
    public wrappercls()
    {
        lstw = new list<InnerClassWrapper>();
        list<Contact> lstcon = [select id,name,phone from Contact];
        for(Contact co : lstcon){
            objICW = new InnerClassWrapper(false, co);
            lstw.add(objICW);
        }
       list<Account> lstacc = [select id,name,phone from Account];
        for(Account ac : lstacc){
            objICW = new InnerClassWrapper(false,ac);
            lstw.add(objICW);
        }
    }
    public class InnerClassWrapper
    {
    public boolean isChecked {get; set;}
    public Contact con {get; set;}
    public Account acc {get; set;}
        
        public InnerClassWrapper(boolean a,Contact b,Account c){
            ischecked = a;
            acc = c;
            con = b;
        }
    }
}

 

 

 

SarfarajSarfaraj
public with sharing class wrappercls {
    
    public InnerClassWrapper objICW {get;set;}
    public list<InnerClassWrapper> lstw {get; set;}
    public wrappercls()
    {
        lstw = new list<InnerClassWrapper>();
        list<Contact> lstcon = [select id,name,phone from Contact];
        for(Contact co : lstcon){
            objICW = new InnerClassWrapper(false, co);
            lstw.add(objICW);
        }
       list<Account> lstacc = [select id,name,phone from Account];
        for(Account ac : lstacc){
            objICW = new InnerClassWrapper(false,ac);
            lstw.add(objICW);
        }
    }
    public class InnerClassWrapper
    {
    public boolean isChecked {get; set;}
    public Contact con {get; set;}
    public Account acc {get; set;}
        
        public InnerClassWrapper(boolean a,Contact b){
            ischecked = a;
            con = b;
        }
		public InnerClassWrapper(boolean a,Account c){
            ischecked = a;
            acc = c;
        }
    }
}

 Not sure about your requirement. But the above will remove the error, and will execute normally.

Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

Hi,

 

You are getting this error because your wrapper class constructor is with 3 parameters. But, while passing the parameter values you are only passing 2 parameters such as Boolean, contact id. Here Account is missing in the constructor parameter.

 

Check the hiighlighted lines,

 

public with sharing class wrappercls {
    
    public InnerClassWrapper objICW {get;set;}
    public list<InnerClassWrapper> lstw {get; set;}
    public wrappercls()
    {
        lstw = new list<InnerClassWrapper>();
        list<Contact> lstcon = [select id,name,phone from Contact];
        for(Contact co : lstcon){
            objICW = new InnerClassWrapper(false, co); //only two parameter values are there instead of three(Account is missing)
            lstw.add(objICW);
        }
       list<Account> lstacc = [select id,name,phone from Account];
        for(Account ac : lstacc){
            objICW = new InnerClassWrapper(false,ac);//Here also only two parameter values are there instead of three(Account is missing)
            lstw.add(objICW);
        }
    }
    public class InnerClassWrapper
    {
    public boolean isChecked {get; set;}
    public Contact con {get; set;}
    public Account acc {get; set;}
        
        public InnerClassWrapper(boolean a,Contact b,Account c){   //Here it is mentioned with 3 parameters
            ischecked = a;
            acc = c;
            con = b;
        }
    }
}

 

 

Hope so this helps you...!

Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.

bittubittu
If i mention 3rd parameter value in loop than i do get Variable does not exist
Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

Have you included the third parameter as Account list?

 

Can you show me the code?

bittubittu
this requirement worked but records are not displaying in vf page
Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

Can you display the code, so its easier to analyse.

bittubittu
public with sharing class wrappercls {

public InnerClassWrapper objICW {get;set;}
public list<InnerClassWrapper> lstw {get; set;}
public wrappercls()
{
lstw = new list<InnerClassWrapper>();
list<Account> lstacc = [select id,name,phone from Account];
list<Contact> lstcon = [select id,name,phone from Contact];
for(Contact co : lstcon){
objICW = new InnerClassWrapper(false, co,lstacc);
lstw.add(objICW);
}
list<Account> lstac = [select id,name,phone from Account];
for(Account ac : lstac){
objICW = new InnerClassWrapper(false,ac);
lstw.add(objICW);
}
}
public class InnerClassWrapper
{
public boolean isChecked {get; set;}
public Contact con {get; set;}
public Account acc {get; set;}

public InnerClassWrapper(boolean a,Contact b,Account c){
ischecked = a;
acc = c;
con = b;
}
}
}