6

I am getting the following error message but i dont know what i am doing wrong. I am trying to create a Map with AggregateResult. I am getting following error message.

Incompatible key type Object for Map

List<AggregateResult> lstShiftOfFund = [SELECT Category_shifted_Into__c catShift,
                                        SUM(How_much_total_reallocated__c)totVal                                                                     
                                        FROM Shift_Funds_Into_This_Category__c
                                        WHERE Funds__c IN :shiftFunSet
                                        GROUP BY Category_shifted_Into__c ];

Map<String,Decimal> mapShiftofFund = new Map<String,Decimal>();


for(AggregateResult aggResult : lstShiftOfFund)
{
mapShiftofFund.put(aggResult.get('catShift'), aggResult.get('totVal'));
}
10

You need to typecast the type of object. like this

for(AggregateResult aggResult : lstShiftOfFund)
{
  mapShiftofFund.put((String)aggResult.get('catShift'), (Decimal)aggResult.get('totVal'));
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.