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,
                                        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'));

1 Answer 1


You need to typecast the type of object. like this

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .