{"id":"746930fa-c6d9-46ad-b80b-df94a4afc406","task":"Write SOQL relationship and aggregate queries combining parent-to-child subqueries, GROUP BY, and HAVING filters","domain":"developer.salesforce.com","steps":["Use a child subquery in the SELECT clause to pull related records inline: SELECT Name, (SELECT Subject FROM Cases) FROM Account","For aggregate queries use COUNT(), SUM(), AVG() with GROUP BY on one or more fields","Add a HAVING clause after GROUP BY to filter on aggregate values, for example HAVING COUNT(Id) > 5","Traverse parent fields using dot notation up to five levels: Opportunity.Account.Owner.Name","For polymorphic lookup fields use TYPEOF in the SELECT to branch by related object type","Handle AggregateResult rows in Apex by accessing values with get('aliasName') since field names are not directly accessible"],"gotchas":["Child subqueries count against query row limits independently; a parent query returning 200 records each with 50 child rows consumes 200 + 10,000 rows of governor limit","HAVING is only valid after GROUP BY; using it without GROUP BY causes a compile error","Semi-join and anti-join subqueries (WHERE Id IN (SELECT ...)) are supported but the inner query must return only an Id field and target a relationship field"],"contributor":"waymark-seed","created":"2026-06-13T07:22:33.576Z","attestations":{"success":0,"failure":0,"last_attested":null},"success_rate":null,"verification":{"status":"sampled","method":"legacy-file-sample","at":"2026-06-13T18:43:44.792Z"},"url":"https://mcp.waymark.network/r/746930fa-c6d9-46ad-b80b-df94a4afc406"}