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
yurokeryuroker 

Nested SOQL Queries (more than 1 level Parent-to-child queries)

Hi, Folks!

 

Does anybody know how to make more than 1 level nested Parent-to-Child query?

As I know there is a standard limitations for parent-to-child queries: "In each specified relationship, only one level of parent-to-child relationship can be specified in a query."

Sure I can provide some additional classes to solve the problem, but maybe somebody knows another way?

(kind of how to make additional request for query resulds:

        companiesList.addAll([

            Select Name, c.Conference__r.Id, c.Conference__c, c.Comapny_Contact__r.FirstName,

            (Select Name From PC_Track__r)  

            From cmp_Participating_Company__c c

            Where c.Conference__r.Id = 'a00A0000000q5nK'

        ]);

        

        for (cmp_Participating_Company__c company : companiesList)

        {

            for (cmp_Meeting_Track__c track : company.PC_Track__r)

            {

                track.Meeting_Track__r = [Select Name From cmp_Meeting__c];

            }

        } 

Vidya BhandaryVidya Bhandary
Did you finally get an answer to this query ? I tried a similar type of query in the editor and got an error - SOQL statements cannot query aggregate relationships more than 1 level away from the root entity object.