Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

str.put('Value',listfield);
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
add comment

2 Answers 2

up vote 2 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>();
listOfStrings.add('Value');

str.put('Value',listOfStrings);

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

str1.put('Value',mapOfListsOfInnerClass);

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

str1.get('Value')

returns

Map<String, List<MyInnerClass>>

The second

getValue('Value')

will return the

List<MyInnerClass>
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 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 Feb 5 '13 at 8:35
1  
I added additional clarification on how to get the objects above. –  Jesse Altman Feb 5 '13 at 15:51
add comment

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
add comment

Your Answer

 
discard

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.