Development questions
Write a SOQL query to fetch Accounts that have both related Contacts AND related Opportunities.
Use two semi-joins combined with AND, one against Contact and one against Opportunity.
soql
SELECT Id, Name FROM Account
WHERE Id IN (SELECT AccountId FROM Contact)
AND Id IN (SELECT AccountId FROM Opportunity)
Both subqueries return Account Ids, so only Accounts present in both are returned.
soqlscenariosemi-join
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?