Development questions
Write a SOQL query to fetch Accounts along with only their Closed Won Opportunities in a subquery (SELECT Id, Name, (SELECT Id, Amount FROM Opportunities WHERE StageName = 'Closed Won') FROM Account).
Filter the child records inside the subquery's own WHERE clause. The parent Accounts are all returned, but each Account's Opportunities list contains only Closed Won rows.
soql
SELECT Id, Name, (SELECT Id, Amount FROM Opportunities WHERE StageName = 'Closed Won') FROM Account
To return only Accounts that have a Closed Won Opportunity, add WHERE Id IN (SELECT AccountId FROM Opportunity WHERE StageName = 'Closed Won') to the outer query.
soqlscenarioparent-to-childsubquery
More Development questions
- What is an Apex Trigger in Salesforce and when should you use it over Flows?
- What is the difference between before triggers and after triggers?
- Explain all Trigger context variables (isInsert, isUpdate, isDelete, isUndelete, isBefore, isAfter, isExecuting, size, operationType).
- What is the difference between Trigger.new and Trigger.old?
- In which trigger events are Trigger.new and Trigger.newMap available?
- In which trigger events are Trigger.old and Trigger.oldMap available?