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

5.43Scenario 2 — retrieve Contacts

Requirement:

Retrieve all Contacts for C001.

Option A:

First find Account ID:

SELECT Id
FROM Account
WHERE External_Customer_ID__c = :customerId

then:

SELECT Id, FirstName, LastName, Email
FROM Contact
WHERE AccountId = :accountId

But you may be able to make it one query:

SELECT
    Id,
    FirstName,
    LastName,
    Email
FROM Contact
WHERE Account.External_Customer_ID__c = :customerId

Cleaner.