Development questions
Write a SOQL query to get the sum, average, minimum, and maximum Opportunity Amount grouped by StageName.
Group Opportunities by StageName and apply all four aggregate functions.
soql
SELECT StageName, SUM(Amount) total, AVG(Amount) average, MIN(Amount) smallest, MAX(Amount) largest
FROM Opportunity
GROUP BY StageName
Each row is an AggregateResult; read values with ar.get('total') and so on.
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?