Development questions
How would you list Contact-only Accounts, meaning Accounts with Contacts but zero Opportunities, using one SOQL query?
Pair a semi-join on Contact with an anti-join on Opportunity in the same WHERE clause. This finds Contact-only Accounts: those with at least one Contact and zero Opportunities.
soql
SELECT Id, Name FROM Account
WHERE Id IN (SELECT AccountId FROM Contact)
AND Id NOT IN (SELECT AccountId FROM Opportunity)
soqlscenariosemi-joinanti-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?