BookatlasTwo-Day MuleSoft → Salesforce Bootcamp
107 / 278 · Module 5 — Salesforce Data Model + SOQL · filtered: code← prev⊞ allnext →

5.48The interview question I promised

Interviewer:

“We need Contacts belonging to Accounts where Status__c = Active and Customer_Type__c = Premium. How would you retrieve them?”

You can answer:

SELECT
    Id,
    FirstName,
    LastName,
    Email,
    Account.Id,
    Account.Name
FROM Contact
WHERE Account.Status__c = 'Active'
AND Account.Customer_Type__c = 'Premium'

And explain:

“Because Contact has a parent relationship to Account, I can traverse that relationship directly in SOQL instead of doing a relational-style JOIN or necessarily issuing two separate queries.”

That is the key answer.