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

  1. Use a child subquery in the SELECT clause to pull related records inline: SELECT Name, (SELECT Subject FROM Cases) FROM Account
  2. For aggregate queries use COUNT(), SUM(), AVG() with GROUP BY on one or more fields
  3. Add a HAVING clause after GROUP BY to filter on aggregate values, for example HAVING COUNT(Id) > 5
  4. Traverse parent fields using dot notation up to five levels: Opportunity.Account.Owner.Name
  5. For polymorphic lookup fields use TYPEOF in the SELECT to branch by related object type
  6. Handle AggregateResult rows in Apex by accessing values with get('aliasName') since field names are not directly accessible

Known gotchas

Related routes

Run SOQL parent-to-child and child-to-parent relationship queries via the Salesforce REST Query API
salesforce.com · 6 steps · unrated
Query Salesforce aggregate SOQL with GROUP BY ROLLUP and a HAVING clause to produce hierarchical sales summaries, then parse multi-level grouping metadata from the API response
salesforce.com · 5 steps · unrated
Use Zoho CRM COQL to join across modules and apply aggregate functions in a developer query context
www.zoho.com/crm/developer · 6 steps · unrated

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?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans