Skip to main content
deleted 33 characters in body
Source Link
Boris Bachovski
  • 16.3k
  • 8
  • 50
  • 88

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>

I am getting this error SObject row was retrieved via SOQL without querying the requested field: Contact.Account

I am sharing my code.

apex code 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 >

     <apex:pageBlock >
         <apex:pageBlockTable value="{!conlist}" var="c">
         
             <apex:column value="{!c.account.Name}"/>
         
         
         
          
         
         
         </apex:pageBlockTable>
     
     
     
     </apex:pageBlock>
     
 
 
 
 </apex:form> 

</apex:page>

I am getting this error:

SObject row was retrieved via SOQL without querying the requested field: Contact.Account

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 >
         <apex:pageBlock >
             <apex:pageBlockTable value="{!conlist}" var="c">
                 <apex:column value="{!c.account.Name}"/>
             </apex:pageBlockTable>
         </apex:pageBlock>
     </apex:form> 
</apex:page>
Source Link
Shantanu Mahajan
  • 984
  • 4
  • 22
  • 46

SObject row was retrieved via SOQL without querying the requested field on Contact.Account

I am getting this error SObject row was retrieved via SOQL without querying the requested field: Contact.Account

I am sharing my code.

apex code 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 >

     <apex:pageBlock >
         <apex:pageBlockTable value="{!conlist}" var="c">
         
             <apex:column value="{!c.account.Name}"/>
         
         
         
         
         
         
         </apex:pageBlockTable>
     
     
     
     </apex:pageBlock>
     
 
 
 
 </apex:form> 

</apex:page>