Write SOQL relationship and aggregate queries combining parent-to-child subqueries, GROUP BY, and HAVING filters
domain: developer.salesforce.com · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗
In-depth guide
Salesforce Bulk API 2.0 limits — the full failure-mode walkthrough related to developer.salesforce.com, checked against official docs, with linked verified routes.
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
Known 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
Give your agent this knowledge — and 15,600+ more routes
One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp
Need this verified for your stack — or a route we don't have yet?