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
Prashant K.Prashant K. 

Constructor not defined: [WrapperController.mywrapper].<Constructor>(List<Account>, List<Contact>)

Hi All,

I am new to the Salesforce Platform.I just try to create the vf page which shows account & contact.I go through the wrapper class concept but got below error.

Constructor not defined: [WrapperController.mywrapper].<Constructor>(List<Account>, List<Contact>)

Please find my code Below.

public class WrapperController {
    
    public class mywrapper
    {
        public Account acc {get;Private set;}
        public Contact con {get;Private set;}
        
        public mywrapper(Account a,Contact c)
        {
        this.acc = a;
        this.con = c;
            
        }
    }
    
        public List<mywrapper> wrapperlist {get;private set;} 
        
        public WrapperController()
        {
            List<Id> accid = new List<Id>();
            List<Account> acclist = new List<Account>([SELECT ID,NAME from Account]);
            for(Account iterateacc:acclist)
            {
                accid.add(iterateacc.id);
                
            }
            this.wrapperlist = new list<mywrapper>();
            List<contact> conlist = new List<Contact>([Select Id, Name FROM Contact Where ID IN :accid]);
            wrapperlist.add(new mywrapper(acclist,conlist));
            }
}


Let me correct If I put it something wrong.Thanks in advance.
Best Answer chosen by Prashant K.
Winder OjedaWinder Ojeda
Hi Prashant K.

Change you wrapper class 

public class mywrapper
    {
        public Account acc {get;Private set;}
        public Contact con {get;Private set;}
        
        public mywrapper(Account a,Contact c)
        {
        this.acc = a;
        this.con = c;
            
        }
    }

to 

public class mywrapper
    {
        public List<Account> acc {get;Private set;}
        public List<Contact> con {get;Private set;}
        
        public mywrapper(List<Account> a, List<Contact> c)
        {
        this.acc = a;
        this.con = c;
            
        }
    }

All Answers

Winder OjedaWinder Ojeda
Hi Prashant K.

Change you wrapper class 

public class mywrapper
    {
        public Account acc {get;Private set;}
        public Contact con {get;Private set;}
        
        public mywrapper(Account a,Contact c)
        {
        this.acc = a;
        this.con = c;
            
        }
    }

to 

public class mywrapper
    {
        public List<Account> acc {get;Private set;}
        public List<Contact> con {get;Private set;}
        
        public mywrapper(List<Account> a, List<Contact> c)
        {
        this.acc = a;
        this.con = c;
            
        }
    }
This was selected as the best answer
Prashant K.Prashant K.
Thanks a lot Winder ojeda.