I have a Map<id, Map<String, integer>> in which I want to add some records as id will repeat so map will have one id and a set of Map<String, integer> but after checking if map.containsKey then add a Map<String, integer> to Map<id, Map<String, integer>> at this line I am getting error that

Method does not exist or incorrect signature: [Map].add(Map)

Can anyone help me fix this issue. My code :

for(Configured_Item__c configuredItem: configuredItemPartOf.get(basicConfiguredItemId)){
    if(configuredItem.Level__c == 2){
      levelSizes.put('SubSystems', subSystem);
      levelSizeMap.put(configuredItem.id, levelSizes.clone());
    if(configuredItem.Level__c == 4){
      levelSizes.put('Element', systemEle);
        // I am getting error here 

Do any one help me to fix this issue.


I'm not much clear about your use case. But there's no add method in Map Class.

You have to use put(key, value). It'll associate specified key and value. If the key is already existing one it'll return the previous value and replace. So you have to use something like below for that line.


You are trying to add a map to the value you will get from "levelSizeMap.get(configuredItem.id).add(levelSizes);" thats why u are getting the error. mapname.get(key) returns the value for that particular key.

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.