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
Anil Kumar SinghAnil Kumar Singh 

How to write query for fetching record from level 2 child object ?

I am writing SOQL query with respect to Parent like this.

 

Parent --> Level_1_Child  --> Level_2_child

 

Apex code:

 

List<Parent> lstParent =

[

Select  parent.id, parent.name,

(

           select id, name , (Select id, name from Level_2_Child__r)

           from Level_1_Child__r

)

From ParentObject

];

 

But this is not working.

 

VF code :

 

<apex:repeat value="{!lstParent}"  var="rec">

   <apex:outputText value="{!rec.name}" />

         <apex:repeat value="{!rec.Level_1_Child__r}"  var="rec1">

             <apex:outputText value="{!rec1.name}" />

                      <apex:repeat value="{!rec1.Level_2_Child__r}"  var="rec2">

                           <apex:outputText value="{!rec2.name}" />

                       </apex:repeat>

          </apex:repeat>

</apex:repeat>

 

above VF code has no erros , compiles successful, but Apex code is giving error hence i am not able to fetch data from Level 2 child,

If i removed Level 2 child from Apex and VF then All is good.

 

Please help me to get this corrected or any other Gud solution except iterating the Level 1 child to get Level 2 child records.