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 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp