function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
skdevskdev 

Displaying data from subquery.

I want to display data from related records of case, i have written a subquery to retreive all the related child records of the case. In my visual force page i want to be able to display a list of these related records. how can i access these individual records from my nested subquery.

my controller class:

public class relatedRecords{

constructor{}

preview(){

caseList;

dependent(caseList);

}

  public void Dependent(List<Case> c){        c = [Select Id, CaseNumber,

                             (Select id, name from caseNotes__r),                               

     (Select id, name from components__r),                               

     (Select id, name from prods__r),                               

     (Select id, name from org__r),                                

              from Case where id in :c];         

system.debug('Size of Cases '+c.size());    }

}

 

Visual force page:

<apex:page standardController="case" extensions="relatedRecords" showHeader="false" sidebar="false" id="thepage">    <apex:form id="theform">       

<apex:commandButton action="{!preview}" value="Preview"/>      

 <p> <apex:repeat value="{!CaseList}" var="Cas">               

<li> Case : {!Cas.CaseNumber} </li> 

<p>                  

<apex:repeat value="{!Cas.caseNotes__r}" var="cn">        

 <li> caseNotes : {!cn.Name}</li>                                      

    </apex:repeat>   </p>                        

 </apex:repeat>       </p>    </apex:form></apex:page>

 

Error : System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Case.caseNotes__r

 

Is there a way to display the related records in visual force page from a subquery .

Starz26Starz26

Not sure about the complete syntax of your query, but the error you are getting in because you are only pullin the id and name from the object you are querying.

 

You need to also query the notes in order to be able to return it.

skdevskdev

But i am only trying to display the name field from the caseNotes__c object.

Starz26Starz26

Do you need to put the parent object API prior to CaseNotes__r?

 

Try THIS link for an example of something like what you are trying to do but using the Account object.