My rough apex class for a Nested map is

map<string,list<string>> str = new map<string,list<string>>();
map<string, map<string,list<MyInnerClass>>> str1 = new map<string,map<string,list<MyInnerClass>>>();

str1.put( 'StrValue',str); // getting error here 

ncompatible value type MAP<String,LIST<String>> for MAP<String,MAP<String,LIST<Innerclass>>>

How should I declare this value

2 Answers 2


Neither of your declaration lines should work actually. To declare this properly, you would need to write something like:

Map<String,List<String>> str = new Map<String,List<String>>();
List<String> listOfStrings = new List<String>();


Map<String, Map<String,List<MyInnerClass>>> str1 = new Map<String,Map<string,List<MyInnerClass>>>();

List<MyInnerClass> listOfInnerClasses = new List<MyInnerClass>();
listOfInnerClasses.add(new InnerClass());

Map<String, List<MyInnerClass>> mapOfListsOfInnerClass = new Map<String, List<MyInnerClass>>();
mapOfListsOfInnerClass.put('Value', listOfInnerClasses);


This code block displays how to populate your maps and lists properly.

The way to retrieve the list of inner classes would be:

List<MyInnerClass> listOfClasses = str1.get('Value').get('Value');

The first



Map<String, List<MyInnerClass>>

The second


will return the

  • .now I'm having another problem.In str1 say if I get values as value={Value=(subTabnames:[subtab=Tab1, field1=field, field2=field2])}} & so no.now I need to get subtab value from str1.if I use str1.get(value).subtab it is throwing error as Initial term of field expression must be a concrete SObject.How can I get it
    – Eagerin Sf
    Commented Feb 5, 2013 at 8:35
  • 1
    I added additional clarification on how to get the objects above. Commented Feb 5, 2013 at 15:51

In your example .put() calls, in both cases you have problems with the second argument.

In the first case, the second argument should be a list, but you're using a map. In the second, the argument should be a map of list, but you're using a nested map.

  • sorry it's a typo mistake.str.put('Value',listfield); str1.put( 'StrValue',listclass);
    – Eagerin Sf
    Commented Feb 4, 2013 at 14:18

You must log in to answer this question.

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