function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
masthan khanmasthan khan 

hai, i want to print Map<string,List<Account>> in Vf page. kindly guide how to do it.

hai,  i want to print Map<string,List<Account>> in Vf page. kindly  guide how to do it.
Rahul.MishraRahul.Mishra
Hi,

To iterate map on Vf page, you have to create a Set<String> in your controller class which holds the keys of map:
public Set<String> keys {get ; set;}

// Assuming my map is mapOfAccount which holds some data.

Map<String, List<Account>> mapOfAccount  = new Map<String, List<Account>>();

keys  = new Set<String>();
keys  = mapOfAccount .keySet();

Once you get keySet of map in a Set of string , then iterate over set of string to get the data from map, like this:
<apex:page controller="MapController">
<apex:repeat value="{!keys}" var="key">
   <apex:repeat value="{!mapOfAccount[key]}" var="map">
       <Apex:outputText value="{!map}"/> <br/>
   </apex:repeat>
</apex:repeat>
</apex:page>

Mark solved if it does help you.
Raj VakatiRaj Vakati
Here is the code

Refer this link
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_dynamic_vf_maps_lists.htm​
 
public class AccMap {
    public  Map<String, List<Account>> accMap {get;set;}
    
    public AccMap(){
        accMap = new  Map<String, List<Account>>();
        List<Account> accs = [Select Id , Name from Account] ; 
        for(Account acc :accs){
            if(accMap.containsKey(acc.Name)) {
                List<Account> accList = accMap.get(acc.Name);
                accList.add(acc);
                accMap.put(acc.Name, accList);
            } else {
                accMap.put(acc.Name, new List<Account> { acc });
            } 
        }
    }
    
}
 
<apex:page controller="AccMap">
    <apex:repeat value="{!accMap}" var="key">
        <apex:repeat value="{!accMap[key]}" var="map">
            <Apex:outputText value="{!map.Name}"/> <br/>
        </apex:repeat>
    </apex:repeat>
</apex:page>