Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 3 down vote accepted

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

share|improve this answer
.now I'm having another problem.In str1 say if I get values as value={Value=(subTabnames:[subtab=Tab1, field1=field, field2=field2])}} & so 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 Feb 5 '13 at 8:35
I added additional clarification on how to get the objects above. – Jesse Altman Feb 5 '13 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.

share|improve this answer
sorry it's a typo mistake.str.put('Value',listfield); str1.put( 'StrValue',listclass); – Eagerin Sf Feb 4 '13 at 14:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.