You need to sign in to do that
Don't have an account?

Map<String,Map<String,List<String>>> mapOfMaps = new Map<String,Map<String,List<String>>>();
Hello everyone,
can any one explain how to play with bellow map , how its usful in developement . can you provide proper example with below map.
Map<String,Map<String,List<String>>> mapOfMaps = new Map<String,Map<String,List<String>>>();
Thanks to all advance :)
can any one explain how to play with bellow map , how its usful in developement . can you provide proper example with below map.
Map<String,Map<String,List<String>>> mapOfMaps = new Map<String,Map<String,List<String>>>();
Thanks to all advance :)
Please mark as best answer if it solves your query
All Answers
Here you go :
Please mark this as the best answer if this helps
Please mark as best answer if it solves your query
Hello Anup,
could you please explain the below code, i have seen it in my org code also, why do we use the below lines. even we dont have any data.
i worte testclasses. that time these lines always failed. i am really big head breaking with bellow line of code and use of it.
Thanks
Line 2: Getting the List of Cities Corresponding to the State and then adding the City to the List.
Line 3: Nothing ;)
Please Mark as best Answer it it Solves your query.
-->
My Controller Class -->
public class MapOfMap {
public Map<String,Map<String,List<String>>> mapOf{get;set;}
Public MapOfMap(){
mapOf =new Map<String,Map<String,List<String>>>();
Map<String,List<String>> map1 = new Map<String,List<String>>();
String[] str1 = new String[]{'mango','pineapple','apple','gavava'};
String str1Id = 'fruits';
map1.put(str1Id, str1);
String[] str2 = new String[]{'abcd','efgh','ijkl','mnop','qrst','uvwx'};
String str2Id = 'alpha';
map1.put(str2Id, str2);
mapOf.put('val1', map1);
/* Second Entry */
Map<String,List<String>> map2 = new Map<String,List<String>>();
String[] str3 = new String[]{'1234','4567','6789','1234'};
String str3Id = 'num';
map2.put(str3Id, str3);
String[] str4 = new String[]{'up','new-delhi','hriyana','lucknow'};
String str4Id = 'state';
map2.put(str4Id, str4);
String[] str5 = new String[]{'Virat','Dhoni','Yuraj','Shami','Pandya'};
String str5Id = 'Team';
map2.put(str5Id, str5);
mapOf.put('val2', map2);
}
}
My Visual force page for accessing map -->
<apex:page controller="MapOfMap">
<apex:repeat value="{!mapOf}" var="key1"> <!--Outer map key = key1 -->
<apex:pageBlock title="{!key1}">
<apex:repeat value="{!mapOf[key1]}" var="key2"> <!--Inner map key = key2 -->
<apex:pageBlockSection title="{!key2}">
<apex:outputText value = "{!mapOf[key1][key2]}" />
</apex:pageBlockSection>
</apex:repeat>
</apex:pageBlock>
</apex:repeat>
</apex:page>
cities.add(new TestCitiesWrapper('Mesa','Arizona','US'));
cities.add(new TestCitiesWrapper('Phoenix','Arizona','US'));
cities.add(new TestCitiesWrapper('Miami','Florida','US'));
cities.add(new TestCitiesWrapper('Patna','Bihar','IN'));
cities.add(new TestCitiesWrapper('Samastipur','Bihar','IN'));
cities.add(new TestCitiesWrapper('Brisbane','Queensland','AU'));
cities.add(new TestCitiesWrapper('Caboolture','Queensland','AU'));
cities.add(new TestCitiesWrapper('Airdrie','Alberta','CA'));
cities.add(new TestCitiesWrapper('Camrose','Alberta','CA'));
Map<String,Map<String,List<String>>> mapOfMaps = new Map<String,Map<String,List<String>>>();
for(TestCitiesWrapper cityObj : cities){
if(mapOfMaps.containsKey(cityObj.country)){
if(mapOfMaps.get(cityObj.country).containsKey(cityObj.state)){
mapOfMaps.get(cityObj.country).get(cityObj.state).add(cityObj.cityName);
}else{
mapOfMaps.get(cityObj.country).put(cityObj.state, new List<String>{ cityObj.cityName });
}
}
else{
List<String> cities = new List<String>();
cities.add(cityObj.cityName);
Map<String,List<String>> mapStateCity = new Map<String,List<String>>();
mapStateCity.put(cityObj.state,cities);
mapOfMaps.put(cityObj.country,mapStateCity);
}
}
system.debug('mapOfMaps==' + mapOfMaps);
public Class TestCitiesWrapper{
public String cityName{ get; set; }
public String state{ get; set; }
public String country{ get; set; }
public TestCitiesWrapper(String cityName, String state, String country){
this.cityName = cityName;
this.state = state;
this.country = country;
}
}
This is properly working..Map withing map of list.. Please Mark as best Answer it it Solves your query.
Map<String,Map<String,List<opportunity>>> mapwithOppOwnerName = new Map<String,Map<String,List<opportunity>>>();
for(Opportunity opp : oppList){
if(mapwithOppOwnerName.containsKey(opp.Owner.Name)){
if(mapwithOppOwnerName.get(opp.Owner.Name).containsKey(opp.Account.Name)){
mapwithOppOwnerName.get(opp.Owner.Name).get(opp.Account.Name).add(opp);
}else{
mapwithOppOwnerName.get(opp.owner.name).put(opp.Account.Name, new List<Opportunity>{ opp});
}
}
else{
List<Opportunity> oppNewList = new List<Opportunity>();
oppNewList.add(opp);
Map<String,List<opportunity>> newMap = new Map<String,List<opportunity>>();
newMap.put(opp.Account.Name,oppNewList);
System.debug('stateToCities-->'+newMap);
mapwithOppOwnerName.put(opp.Owner.Name,newMap);
}
}