I have some code that does a series of "group by" queries, and uses a common method (apply
) to process the results:
for (AggregateResult ar : [
select PaymentSpecification__c id, Status__c status, sum(Net__c) net
from Payment__c
where PaymentSpecification__c in :psIds
group by PaymentSpecification__c, Status__c
]) {
apply(ar);
}
for (AggregateResult ar : [
select PaymentSpecification__c id, sum(Net__c) net
from UnallocatedPayment__c
where PaymentSpecification__c in :psIds
group by PaymentSpecification__c
]) {
apply(ar);
}
In some cases one of the result values "status" is not present in the data. Ideally I would like that value to go through into the method as null.
At the moment I am not setting the value (as shown in the second query) and get this runtime error:
Invalid field status for AggregateResult
Is there any way of injecting a constant (and ideally null) to take the place of real data using the alias "status" in this situation?
(Obviously I can code around this; just want to know if there is any SOQL syntax available that helps.)