Run SOQL parent-to-child and child-to-parent relationship queries via the Salesforce REST Query API

domain: 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 salesforce.com, checked against official docs, with linked verified routes.

Steps

  1. For child-to-parent (many-to-one) traversal, use dot notation in the SELECT clause: SELECT Id, Account.Name FROM Contact WHERE Account.Industry = 'Technology'.
  2. For parent-to-child (one-to-many) sub-queries, embed a SELECT inside the FROM clause: SELECT Id, Name, (SELECT Id, CloseDate FROM Opportunities) FROM Account.
  3. GET or POST to /services/data/vXX.0/query?q={URL-encoded SOQL}; use POST /services/data/vXX.0/query for long queries that exceed URL length limits.
  4. The response includes 'totalSize', 'done', and 'records'; if 'done' is false, follow 'nextRecordsUrl' to paginate until done is true.
  5. For sub-query results, each parent record's sub-query results are nested under the relationship name with their own 'records' array and 'done'/'nextRecordsUrl' if the child result set is large.
  6. Use LIMIT and OFFSET or cursor-based pagination (nextRecordsUrl) rather than OFFSET alone for large datasets, as OFFSET beyond 2,000 is not supported.

Known gotchas

Related routes

Write SOQL relationship and aggregate queries combining parent-to-child subqueries, GROUP BY, and HAVING filters
developer.salesforce.com · 6 steps · unrated
Run a SOQL query with pagination from the Salesforce API
salesforce.com · 4 steps · unrated
Insert a parent record with multiple related child records in one request using the Salesforce sObject Tree API
salesforce.com · 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