I am getting this error SObject row was retrieved via SOQL without querying the requested field: Contact.Account
I am sharing my code.
SObject row was retrieved via SOQL without querying the requested field: Contact.Account
apex code public class WrapperAccountCtrl {Controller:
public class WrapperAccountCtrl {
public List<Account> acclist{get;set;}
public List<Contact> conlist{get;set;}
public List<MyWrapper> wap{get;set;}
public WrapperAccountCtrl()
{
acclist=[Select id,name from Account];
conlist=[Select id,name,AccountID from contact where AccountID IN:acclist];
system.debug('Size----'+conlist.size());
wap=new List<MyWrapper>();
for(integer i=0;i<acclist.size();i++)
{
wap.add(new MyWrapper(conlist,acclist[i]));
}
}
public class MyWrapper
{
public Account accn{get;set;}
public List<Contact>conrec{get;set;}
public MyWrapper(List<Contact> con,Account acc)
{
accn=acc;
conrec=con;
}
}
}
}
vf page <apex:page controller="WrapperAccountCtrl" sidebar="false"> <apex:form >VF Page:
<apex:page controller="WrapperAccountCtrl" sidebar="false">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!conlist}" var="c">
<apex:column value="{!c.account.Name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
</apex:page>