Below code throws this error:

Method does not exist or incorrect signature: void put(String, String) from the type Map<String,Map<String,String>>


//I have this map
Map <String,Map <String,String>> MapFist= new Map <String,Map<String,String>>();

//I need the popular map with these values

MapFist.put('FiestIndex', 'SecondIndex','Value');
  • What does "popular" mean to you in this context? Can you add some more description to your question of what you are trying to do? – David Reed Feb 4 '19 at 23:43
  • I want to fill the map with the values ​​of the "put" Note that in has three strings I need to add the 3 within the map – Studentha Feb 4 '19 at 23:45

You need to access each nested map level individually. Always make sure you initialize the inner layers before you attempt to use them (or you'll get a NullPointerException).

MapFist.put('FiestIndex', new Map<String, String>());
MapFist.get('FiestIndex').put('SecondIndex', 'Value');
  • I could do this dynamically through a loop of repetition? – Studentha Feb 5 '19 at 0:14
  • @Studentha Yes, you can. Just check for nulls first, if necessary. – sfdcfox Feb 5 '19 at 0:30
  • Not to null these values ​​that you made with the put method will come from another map, it will be "one map inside another" haha – Studentha Feb 5 '19 at 0:34
  • Are you in any material for me to refer to? – Studentha Feb 5 '19 at 1:08
  • @Studentha salesforce.stackexchange.com/a/40310 is one such example of a multi-layer map populated dynamically. It's not quite the same as whatever you're doing, but close enough for practical purposes. – sfdcfox Feb 5 '19 at 1:12

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.