Development questions
Write a SOQL query to count the number of Contacts associated with each Account (SELECT AccountId, COUNT(Id) FROM Contact GROUP BY AccountId).
Aggregate Contacts grouped by AccountId.
soql
SELECT AccountId, COUNT(Id) total FROM Contact
WHERE AccountId != null
GROUP BY AccountId
In Apex: (Id) ar.get('AccountId') and (Integer) ar.get('total').
soqlscenarioaggregategroup-by
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?