You need to sign in to do that
Don't have an account?

How to handle SOQL parent-to-child query in 2-levels?
I am trying to query Account-Opportunity-OpportunityLineItem using the query below. It does not work and I am aware the documentation says SOQL queries only manages 1-level of parent-to-child relationship...
However, is there any trick I can use to rewrite the query without the need of running two separated queries?
SELECT Account.Name,
(SELECT Opportunity.Name, (SELECT OpportunityLineItem.Description FROM OpportunityLineItems)
FROM Opportunities) FROM Account
Instead traverse from child to parent
All Answers
Instead traverse from child to parent
Yes that would be a possibility, but it would not result in the same hierarchical result.
I had hoped to be able to create a result where you go from each account and then down to a list of Opportunities and OpportunityLineItems under each respective account. Going from child to parent will give a result the other way around, if I am not mistaken.
But thanks anyway