I need to add a variable to an Aggregate Result list.
In the semi pseudocode below I attempt to assign a value to the AggregateResult[]
if the sum is 0.
This does not work. The aggRes
is later used in a function and I do not want to have to put the results of the aggregate result into a map for a solution.
Is it possible to accomplish what I'm doing and directly modify the AggregateResult
?
AggregateResult[] aggRes = [Select Expense__c, Sum(Cost__c) from CustomObject__c Group By Expense__c];
for(AggregateResult ar: aggRes) {
if(ar.get(Cost__c) == 0) {
ar.put(Cost__c, 10);
}
}
Best Answer
No. If you attempt to modify the AggregateResult, you'll get a runtime error. Here's an example from my dev org:
Result:
The documentation also states that the object is read-only, so it is not possible to modify the values within the result object.