You need to sign in to do that
Don't have an account?

unknown property error in salesforce
I am trying to learn Wrapper class in Salesforce development but I am getting the below error, could some one please help me te resolve this error.
Below are the error details, Apex code and VFPage code
Error:
Unknown property 'Wrapperclass.lstWrapperDisplay'
VFPage code:
<apex:page controller = "Wrapperclass">
<apex:form>
<apex:pageBlock >
<apex:pageBlockSection>
<apex:pageBlockTable value="{!lstWrapperDisplay}" var="w">
<apex:column headerValue="Action">
<apex:inputCheckbox/>
</apex:column>
<apex:column headerValue="Account Name">
{!w.accname}
</apex:column>
<apex:column headervalue="Account Number">
{!w.accnum}
</apex:column>
<apex:column headervalue="Industry">
{!w.accind}
</apex:column>
<apex:column headervalue="Opportunity Name">
{!w.oppname}
</apex:column>
<apex:column headervalue="Opportunity Amount">
{!w.oppamt}
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex class
public class Wrapperclass {
public Wrapperclass(){
lstAcc = new List<Account>();
lstOpp = new List<Opportunity>();
}
//Name, accountnumber,Industry from Account
//Name, ammount from opportunity
//Instanitate List for Account, Opportunity
public List<Account> lstAcc {get;set;}
public List<Opportunity> lstOpp {get;set;}
//List for Wrapper Class
public List<Wrapper> lstw;
public void lstWrapperDisplay(){
lstAcc = [select name,accountnumber,Industry from Account];
lstOpp = [select name,amount from Opportunity];
for(integer i=0;i<lstOpp.size();i++){
lstw.add(new Wrapper(lstAcc[i].name,lstAcc[i].accountnumber, lstAcc[i].Industry,lstOpp[i].name,lstOpp[i].amount));
}
//return lstw;
}
public class Wrapper{
public String accname {set;get;}
public String accnum {set;get;}
public String accind {set;get;}
public String oppname {set;get;}
public Decimal oppamt {set;get;}
public Wrapper(String accname, String accnum, String accind, String oppname, Decimal oppamt){
this.accname = accname;
this.accnum = accnum;
this.accind = accind;
this.oppname = oppname;
this.oppamt = oppamt;
}
}
}
Below are the error details, Apex code and VFPage code
Error:
Unknown property 'Wrapperclass.lstWrapperDisplay'
VFPage code:
<apex:page controller = "Wrapperclass">
<apex:form>
<apex:pageBlock >
<apex:pageBlockSection>
<apex:pageBlockTable value="{!lstWrapperDisplay}" var="w">
<apex:column headerValue="Action">
<apex:inputCheckbox/>
</apex:column>
<apex:column headerValue="Account Name">
{!w.accname}
</apex:column>
<apex:column headervalue="Account Number">
{!w.accnum}
</apex:column>
<apex:column headervalue="Industry">
{!w.accind}
</apex:column>
<apex:column headervalue="Opportunity Name">
{!w.oppname}
</apex:column>
<apex:column headervalue="Opportunity Amount">
{!w.oppamt}
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex class
public class Wrapperclass {
public Wrapperclass(){
lstAcc = new List<Account>();
lstOpp = new List<Opportunity>();
}
//Name, accountnumber,Industry from Account
//Name, ammount from opportunity
//Instanitate List for Account, Opportunity
public List<Account> lstAcc {get;set;}
public List<Opportunity> lstOpp {get;set;}
//List for Wrapper Class
public List<Wrapper> lstw;
public void lstWrapperDisplay(){
lstAcc = [select name,accountnumber,Industry from Account];
lstOpp = [select name,amount from Opportunity];
for(integer i=0;i<lstOpp.size();i++){
lstw.add(new Wrapper(lstAcc[i].name,lstAcc[i].accountnumber, lstAcc[i].Industry,lstOpp[i].name,lstOpp[i].amount));
}
//return lstw;
}
public class Wrapper{
public String accname {set;get;}
public String accnum {set;get;}
public String accind {set;get;}
public String oppname {set;get;}
public Decimal oppamt {set;get;}
public Wrapper(String accname, String accnum, String accind, String oppname, Decimal oppamt){
this.accname = accname;
this.accnum = accnum;
this.accind = accind;
this.oppname = oppname;
this.oppamt = oppamt;
}
}
}
You have an iteration variable 'lstWrapperDisplay' on your vf page, so to populate this you have 2 options :
1. Define a property with getter and setter in your controller e.g. public list<Wrapper> lstWrapperDisplay{get;set;} :
2. Define a getter method in you controller using syntax : 'get' + [YOURVFPAGEVARIABLENAME], So in your case method name will be 'getlstWrapperDisplay' with return type as 'List<Wrapper>'
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks
All Answers
You have an iteration variable 'lstWrapperDisplay' on your vf page, so to populate this you have 2 options :
1. Define a property with getter and setter in your controller e.g. public list<Wrapper> lstWrapperDisplay{get;set;} :
2. Define a getter method in you controller using syntax : 'get' + [YOURVFPAGEVARIABLENAME], So in your case method name will be 'getlstWrapperDisplay' with return type as 'List<Wrapper>'
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks
Update your code from below code. It will help you because it works for me:
//Vf page
//Apex controller class code
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi