0

Getting the following error at line number 7.

Method does not exist or incorrect signature: void add(Auto_Risk_Fill__c) from the type Map

List<Auto_Risk_Fill__c> autoValues = new List<Auto_Risk_Fill__c>();
autoValues = [SELECT Answer__c,Answer_Comments__c,Risk_Factor_Name__c,Category__c,Opportunity_BidLevel__c,Opportunity_Install_Country__c,Opportunity_Project_Scope__c,P_L__c,Risk_Module__c  FROM Auto_Risk_Fill__c];   
Map<String,Map<String,Auto_Risk_Fill__c>>> mapOfMaps = new Map<String,Map<String,List<Auto_Risk_Fill__c>>>();

    for(Auto_Risk_Fill__c  autoObj : autoValues){
        if(mapOfMaps.containsKey(autoObj.P_L__c)){
        //mapOfMaps.get(autoObj.Risk_Factor_Name__c).add(autoValues);
        System.debug('dsfds'+mapOfMaps);
        }
        else{
            Map<String,Auto_Risk_Fill__c> riskItems = new Map<String,Auto_Risk_Fill__c>();
            riskItems.put(autoObj.Risk_Factor_Name__c,autoObj);
            mapOfMaps.put(autoObj.P_L__c,riskItems);
        }
    }

    System.debug('hey'+mapOfMaps);
1
  • As it a “map of maps” it should be a put not an add.
    – Keith C
    Commented Nov 1, 2018 at 8:48

2 Answers 2

2

you want to get Map<String,Auto_Risk_Fill__c> by autoObj.P_L__c and after that put to this Map put(autoObj.Risk_Factor_Name__c,autoObj).

Your code will look like

List<Auto_Risk_Fill__c> autoValues = [
    select Answer__c, Answer_Comments__c, Risk_Factor_Name__c, Category__c, Opportunity_BidLevel__c, Opportunity_Install_Country__c, Opportunity_Project_Scope__c, P_L__c, Risk_Module__c
    from Auto_Risk_Fill__c
    ];   

Map<String,Map<String,Auto_Risk_Fill__c>>> mapOfMaps = new Map<String,Map<String, Auto_Risk_Fill__c>>();
    for(Auto_Risk_Fill__c  autoObj : autoValues){
        Map<String, Auto_Risk_Fill__c> riskItems = null;
        if(mapOfMaps.containsKey(autoObj.P_L__c)){
            riskItems = mapOfMaps.get(autoObj.P_L__c);
        }else{
            riskItems = new Map<String, Auto_Risk_Fill__c>();          
        }
        riskItems.put(autoObj.Risk_Factor_Name__c, autoObj);
        mapOfMaps.put(autoObj.P_L__c, riskItems);
    }
System.debug('mapOfMaps:' + mapOfMaps);
0

Fifth line is wrong -

Map<String,Map<String,Auto_Risk_Fill__c>>> mapOfMaps = new 
Map<String,Map<String,List<Auto_Risk_Fill__c>>>();

Right and left side structure are not same. Make it same.

You must log in to answer this question.

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