Notes
In Salesforce Apex, AggregateResult[]
is an array type used to store the results of aggregate queries. Aggregate queries allow you to perform calculations on your data, such as counting, summing, averaging, or finding the minimum or maximum values. The AggregateResult
type is specifically designed to work with the results of such queries.
Here's a brief explanation and example of how AggregateResult[]
is typically used:
List<AggregateResult> aggregateResults = [SELECT StageName, COUNT(Id) recordCount, AVG(Amount) avgAmount
FROM Opportunity
GROUP BY StageName];
for (AggregateResult result : aggregateResults) {
Integer count = (Integer)result.get('recordCount');
Decimal avgAmount = (Decimal)result.get('avgAmount');
System.debug('Stage: ' + result.get('StageName') + ', Records: ' + count + ', Average Amount: ' + avgAmount);
}
Output: Stage: Prospecting, Records: 2, Average Amount: 354920.75
Video
Video does not exists.