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

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');

Best Answer

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');