You need to sign in to do that
Don't have an account?
put/add aggregateresult to map
hi,
I am trying to insert data into a parent table based on an aggregate query (table is called receipt__c). I will need to add the results to a map, because I am going to add data to a child table later.
When I run the SOQL query that retreives the aggregate result, I also get a record called concat_donor__c. I want that value in my map because I will need it when I add the child records (concat_donor__c will determine which receipt__c records each child record should be associated with).
The line of code "receiptmap.put(ar.get('Transaction__r.concat_donor__c'), r);"
results in: "Error: Compile Error: Incompatible key type Object for MAP<String,receipt__c> at line 33 column 9".
How should I be doing this? If anyone could point me in the right direct I'd really appreciate it.
--------------------------
List<receipt__c> receipts = new List<receipt__c>();
Map<String, receipt__c> receiptmap = new Map<String, receipt__c>();
List<aggregateResult> aloc = [SELECT sum(receiptable__c)tot, Transaction__r.concat_donor__c from Allocation__C WHERE receiptable__c > 0 AND Transaction__c not in (select transaction__c from Donation_Receipt_Link__c) group by Transaction__r.concat_donor__c];
for (AggregateResult ar : aloc)
{
receipt__c r = new receipt__c();
r.Amount__c = (Decimal) ar.get('tot');
receipts.add(r);
receiptmap.put(ar.get('Transaction__r.concat_donor__c'), r);
}
insert receipts;
Can you try casting ar.get('Transaction__r.concat_donor__c') to a String?
All Answers
Can you try casting ar.get('Transaction__r.concat_donor__c') to a String?
that was a quick fix- thanks!