Five-Level Parent-to-Child Relationship SOQL Queries in Apex
Apex now supports traversing up to five levels of parent-child records with SOQL relationship queries. Each subquery counts towards the aggregate queries processed in an SOQL query statement.
Starting from API version 61.0, SOQL parent-child relationship queries in Apex can be structured such that the first level of the query is a parent root, and child relationships can be queried up to four levels deep from the parent root. You can keep track of the number of aggregate queries processed in an SQL statement using the Limits.getAggregateQueries() method. The Limits.getLimitAggregateQueries() method returns a value of 300, the total number of aggregate queries that can be processed with SOQL query statements. This change applies to all editions.
Below is an example of a Salesforce SOQL query statement with five levels of parent-child relationships.
List<Account> accts =
[SELECT Name,
(SELECT LastName,
(SELECT AssetLevel,
(SELECT Description,
(SELECT LineItemNumber FROM WorkOrderLineItems)
FROM WorkOrders)
FROM Assets)
FROM Contacts)
FROM Account];
References -
Five-Level Parent-to-Child Relationship SOQL Queries in Apex
Comments
Post a Comment