+ Start a Discussion
PERFECTIONISTPERFECTIONIST 

SOQL: Parent to Child and Child to sub child relationship

Dear All,

Here i am posting a challenging question for all salesforce developers.

Can we fetch Data from Parent to child and child to sub child, sub child to child?

Let me explain you bit more:
 have Parent table A and child is B 
                           B having relation ship with C
                           C having relation ship with D
Now my question is i need to get data of A + B + C+ D by using SOQL query

Note: we need to get data by writing SOQL Query only not in using apex list or map

Highly apreciable your valueble answers

Thanks,


 
Anupam RastogiAnupam Rastogi
Hi Sathish,

If you are talking about retrieving values from all these different objects within one SOQL then that is not possible. But you can use different SOQLs to pull data.

Like if you run the following SOQL then you will receive an error stating "SOQL statements cannot query aggregate relationships more than 1 level away from the root entity object.".
select Name, (select Name, (select Name from Quotes) from Opportunities) from Account

Therefore you need to break down the SOQL and then run it.

Thanks
AR

If you found the reply useful that solves your problem then please mark it as best answer.
KaranrajKaranraj
Sathish - SOQL statements cannot query aggregate relationships more than 1 level away from the root entity object. You have to breakdown your SOQL query and run it.