Any Idea on how to solve this error?


Map<Integer,Map<String,Decimal>> BERYear = new Map<Integer,Map<String,Decimal>>();
    List<Budget_Exchange__c> beList = [Select Code__c, USD__c from Budget_Exchange__c];
    Map<String, Decimal> bemap = new Map<String, Decimal>();
    for (Budget_Exchange__c b : beList)

        BERYear.put(b.Fiscal_Year__c,bemap.put(b.Code__c, b.USD__c)); //ERROR HERE

Error: Incompatible key type Decimal for Map(Integer,Map(String,Decimal))

  • 1
    Your field Fiscal_Year__c looks to be type of Decimal, while your Map requires an Integer. Change the map into Map<Decimal,Map<String,Decimal>> and try again. Also make sure to include the field Fiscal_Year__c` in your query.
    – highfive
    Oct 12, 2015 at 8:25
  • Correcting as you suggest, the error change, I've reported it below. Oct 12, 2015 at 8:33

1 Answer 1


You define the map here

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

You have defined that the key must be a decimal, and the value must be a Map of String to Decimal.

Then you use the map here

BERYear.put(b.Fiscal_Year__c,bemap.put(b.Code__c, b.USD__c)); //ERROR HERE

Here you are putting b.Fiscal_Year__c into the key. If b.Fiscal_Year__c is a decimal then this is fine.

What are you putting into the value? You are putting the result of bemap.put(b.Code__c, b.USD__c) The result of a map.put is, if the map previously contained a mapping for this key, the old value is returned by the method and then replaced. The result of the put is NOT a map.

You should PUT your value into the map on a separate statement.

bemap.put(b.Code__c, b.USD__c);

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.