1

Below code throws this error:

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

Code:

//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');
2
  • 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
    Commented Feb 4, 2019 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
    Commented Feb 4, 2019 at 23:45

1 Answer 1

1

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');
6
  • I could do this dynamically through a loop of repetition?
    – Studentha
    Commented Feb 5, 2019 at 0:14
  • @Studentha Yes, you can. Just check for nulls first, if necessary.
    – sfdcfox
    Commented Feb 5, 2019 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
    Commented Feb 5, 2019 at 0:34
  • Are you in any material for me to refer to?
    – Studentha
    Commented Feb 5, 2019 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
    Commented Feb 5, 2019 at 1:12

You must log in to answer this question.

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