+ Start a Discussion
Vishnu7700Vishnu7700 

Constructor not defined

Hi,

I'm trying to create a VF page to mass update the account.Created VF page and on controller i'm trying to put logic with wrapper class concept,but i'm getting error as  Constructor not defined: [massEditComponentController.AccountWrapper].<Constructor>(SOBJECT:Account) at line 36 column 25

Even though i defined the constructor for wrapper calss.Can any one help out how to resolve this issue.

VF code:

<apex:pageBlockTable value="{!Accountrecords}" var="recwrap" id="records">

Controller:

public class massEditComponentController {
    public List<Account> Accountrecords{get;set;}    
    public List<Account> accountslist{get;set;}
    public List<AccountWrapper> AccountWrapList{get;set;}
    public string fileItems{get;set;}
    public string inputVal {get;set;}
    public string selectedField{get;set;}
    Public List<string> AccountfieldList{get;set;}
   
    //Constuct class
    public massEditComponentController(){
     AccountWrapList = New List<AccountWrapper>();        
     }
   
    public List<SelectOption> getfileItems(){
    List<SelectOption> options = new List<SelectOption>();
    for(string st:AccountfieldList)
    options.add(new SelectOption(st,st));
    return options;
    }
   
    public PageReference deleteRecords() {
    List<Account> accToDel = new List<Account>();
    /*for(accountslist wrp : AccountWrapList){
    //Check if record is selected
    if(wrp.isSelected){
    accToDel.add(wrp.myaccount);
     }
      }*/
        return null;
    }
    //Method to query accounts record and populate in wrapper
    public List<AccountWrapper> gerAccountrecords(){
    AccountWrapList.clear();   
    for (Account acc:accountslist)
    AccountWrapList.add(New AccountWrapper (acc));
    return AccountWrapList;       
    }
    public PageReference updateSelectedRecords() {
        return null;
    }
    public pagereference BackToHomeBtnClick(){
        pagereference homepage = new pagereference('/home/home.jsp');
        homepage.setredirect(true);
        return homepage ;
    }
     //WrapperCLass
      public class AccountWrapper{
        public boolean isSelected{get;set;}
        public Account myaccount{get;set;}  
        public boolean checkBox{get;set;} 
              //Constructor
        public AccountWrapper(Account myaccount,Boolean isSelected,Boolean checkBox){
          this.myaccount = myaccount;

          }
}


      }

Error was created on the line marked in red.

 

 

sambasamba

AccountWrapList.add(New AccountWrapper (acc)); the AccountWrapper's constructor method has two params. You lost one.

 

 

 

Thanks,

Samba

 

 

sambasamba

no two, it's three.

Vishnu7700Vishnu7700

Hi All,

Corrected my code as you all said and i'm faceing error as Error: Invalid field isSelected for SObject Account

on below controller code

 

public class massEditComponentController {
    public List<Account> Accountrecords{get;set;}    
    public List<Account> accountslist{get;set;}
    public List<AccountWrapper> AccountWrapList{get;set;}
    public string fileItems{get;set;}
    public string inputVal {get;set;}
    public string selectedField{get;set;}
    Public List<string> AccountfieldList{get;set;}
   
    //Constuct class
    public massEditComponentController(){
     AccountWrapList = New List<AccountWrapper>();        
     }
   
    public List<SelectOption> getfileItems(){
    List<SelectOption> options = new List<SelectOption>();
    for(string st:AccountfieldList)
    options.add(new SelectOption(st,st));
    return options;
    }
    //Method to query accounts record and populate in wrapper
    public List<AccountWrapper> gerAccountrecords(){
    AccountWrapList.clear();   
    for (Account acc:[SELECT Name,Phone,BillingCity,WebSite FROM Account]){
    AccountWrapList.add(New AccountWrapper (acc,false));
    }
     return AccountWrapList;      
    }
    public PageReference deleteRecords() {
    List<Account> accToDel = new List<Account>();
    /*for(accountslist wrp : AccountWrapList){
    //Check if record is selected
    if(wrp.checkBox == true){
    accToDel.add(wrp.myaccount);
     }
      }*/
        return null;
    }
    

   
    public PageReference updateSelectedRecords() {
        return null;
    }
    public pagereference BackToHomeBtnClick(){
        pagereference homepage = new pagereference('/home/home.jsp');
        homepage.setredirect(true);
        return homepage ;
    }
     //WrapperCLass
      public class AccountWrapper{
        public Account myaccount{get;set;}  
        public boolean checkBox{get;set;} 
              //Constructor
        public AccountWrapper(Account myacc,Boolean selectFlag){
          myaccount = myacc;
          checkBox = checkBox;
          }
}


      }

Avidev9Avidev9

You are overlooking the basics here.

 

If you want a quick fix it should be

 

   AccountWrapList.add(New AccountWrapper (acc,false,false));

 But since you havent defined a constructor with one parameters for your wrapper class you are getting an error.

Vishnu7700Vishnu7700

Hi Avidev9,

Defined constructor haveing only 2 parameters.

Can you pls have look on this.

Avidev9Avidev9

Vishnu I will scold you!

if you have defined two parameters then pass only two. 

 

AccountWrapList.add(New AccountWrapper (acc,false));
sambasamba

Can you send your develop edition to me. I will check it when i have some time.

 

 

Thanks,

Samba

Vishnu7700Vishnu7700

Yup sure...

Please find the controller code

public class massEditComponentController {
    public List<Account> Accountrecords{get;set;}    
    //public List<Account> accountslist{get;set;}
    public List<AccountWrapper> AccountWrapList{get;set;}
    public string fileItems{get;set;}
    public string inputVal {get;set;}
    public string selectedField{get;set;}
    Public List<string> AccountfieldList{get;set;}
   
    //Constuct class
    public massEditComponentController(){
     AccountWrapList = New List<AccountWrapper>();        
     }
   
    public List<SelectOption> getfileItems(){
    List<SelectOption> options = new List<SelectOption>();
    for(string st:AccountfieldList)
    options.add(new SelectOption(st,st));
    return options;
    }
    //Method to query accounts record and populate in wrapper
    public List<AccountWrapper> gerAccountrecords(){
    AccountWrapList.clear();   
    for (Account acc:[SELECT Name,Phone,BillingCity,WebSite FROM Account]){
    AccountWrapList.add(New AccountWrapper (acc,false));
    }
     return AccountWrapList;      
    }
    public void deleteRecords() {
    List<Account> accToDel = new List<Account>();
    for(AccountWrapper wrp : AccountWrapList){
    //Check if record is selected
    if(wrp.checkBox == true){
    accToDel.add(wrp.myaccount);
     }
      }
        delete accToDel;
    }
    

   
    public void updateSelectedRecords() {
        List<Account> accountslist = New List<Account>();
     for(AccountWrapper wr: AccountWrapList){
         if(wr.checkBox == true ){
            wr.myaccount.put(selectedField,inputVal);
         }   
         accountslist.add(wr.myaccount);
     }
     Update accountslist;
    }
    public pagereference BackToHomeBtnClick(){
        pagereference homepage = new pagereference('/home/home.jsp');
        homepage.setredirect(true);
        return homepage ;
    }
     //WrapperCLass
      public class AccountWrapper{
        public Account myaccount{get;set;}  
        public boolean checkBox{get;set;} 
              //Constructor
        public AccountWrapper(Account myacc,Boolean selectFlag){
          myaccount = myacc;
          checkBox = checkBox;
          }
}


      }