-1

I am trying to add map of map values, I have to intialize the map key first and then try to add value later. Below is the exact logic i am trying to achieve.

Map<string,Map<string,List<string>>> finalMap = new Map<string,Map<string,List<string>>>();

Map<string,List<string>> subMap = new Map<string,List<string>>();
submap.put('One',new list<string>{'One','TWO'});

finalMap.put('SUB1',new Map<string,List<string>>());

//Do some logics and finally try to add the values with the key

finalmap.get('SUB1').put(subMap); //Error as stated below

System.debug(finalmap);

ERROR :Method does not exist or incorrect signature: [Map<String,List<String>>].put(Map<String,List<String>>)

2

If you want to add a map onto existing map, use putAll() method.

finalMap.get('DETAILS').putAll(subDetails); 

It will add the entries of subDetails onto whatever Map finalMap contains aganist key 'DETAILS'.

|improve this answer|||||
0

You have to add like below

finalMap.put('DETAILS',subDetails); 

OR

Get the existing value and den update it like below

Map<string,List<string>> subDetails= finalMap .get('DETAILS')
//-- Do your business logic to update subDetails and then add as below
finalMap.put('DETAILS',subDetails); 
|improve this answer|||||

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.