BookatlasTwo-Day MuleSoft → Salesforce Bootcamp
10 / 81 · Module 5 — Salesforce Data Model + SOQL · filtered: interview← prev⊞ allnext →

5.23Parent → Children

Now go the other direction.

Account
  │
  ├── Contact
  ├── Contact
  └── Contact

Question:

Get Accounts and their Contacts.

You use a subquery:

SELECT
    Id,
    Name,
    (
        SELECT
            Id,
            FirstName,
            LastName,
            Email
        FROM Contacts
    )
FROM Account

Key detail:

FROM Contacts

not necessarily:

FROM Contact

because here you use the child relationship name.

This is something Salesforce developers often have to inspect from metadata rather than guess for custom relationships.