Development questions
Write a SOQL query to fetch Accounts that have NO related Contacts (Anti-Join using WHERE Id NOT IN (SELECT AccountId FROM Contact)).
Use an anti-join: WHERE Id NOT IN (SELECT AccountId FROM Contact).
soql
SELECT Id, Name FROM Account WHERE Id NOT IN (SELECT AccountId FROM Contact)
Returns Accounts with no Contacts. Note the subquery results are limited by the platform for semi/anti-joins, and AccountId is a lookup so the clause is valid.
soqlscenarioanti-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?