I'm getting this error while running this VF Page
Error is: SObject row was retrieved via SOQL without querying the requested field: Attachment.ParentId
VF Page:
<apex:page showHeader="false" controller="Controller004" sidebar="false" >
<apex:messages />
<apex:pageBlock >
<apex:pageBlockSection title="Record of avalaible Doctors" >
<apex:form >
<apex:pageBlockTable value="{!wc}" var="a" columns="4" cellpadding="15px">
<apex:column headerValue="Name">
<apex:outputField value="{!a.doctor.Full_Name__c}" />
</apex:column>
<apex:column headerValue="Fee">
<apex:outputField value="{!a.doctor.Fee__c}"/>
</apex:column>
<apex:column headerValue="Schedule">
<apex:outputField value="{!a.doctor.schedule__c}"/>
</apex:column>
<apex:column headerValue="Photo" >
<apex:image url="{!a.url}" height="300px" width="200px" />
</apex:column>
</apex:pageBlockTable>
</apex:form>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
Controller of this page is:
global class Controller004{
public List<Doctor__c> obj {get;set;}
public List<WrapperClass> wc{get;set;}
public Controller004(){
obj=[select Full_Name__c, Fee__c, schedule__c from Doctor__c];
Map<Id,Id> mapDocToAtt = new Map<Id,Id>();
for(Attachment a : [select id from Attachment where ParentId in:obj])
{
mapDocToAtt.put(a.ParentId, a.Id);
}
for(Doctor__c doctor : [select Full_Name__c, Fee__c, schedule__c from Doctor__c])
{
wc = new List<WrapperClass>();
wc.add(new WrapperClass(doctor, '/servlet/servlet.FileDownload?file='+mapDocToAtt.get(doctor.Id)));
}
}
public class WrapperClass{
public Doctor__c doctor{get;set;}
public String url{get;set;}
public WrapperClass(Doctor__c doctor, String url){
this.doctor=doctor;
this.url=url;
}
}
}