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

Create a map to store account name as key and corresponding opportunities as values.Display that map in VF page
Final output comming as Account and Opportunity ID. i want to display Account name and opportunity names
public class Map_Opportunities {
public Map<string,List<Opportunity>> oppMap {set;get;}
public List<Opportunity> optyList {set;get;}
public Map_Opportunities(){
oppMap = new Map<string,List<Opportunity>>();
for (Account acc: [SELECT name,(SELECT Name FROM Opportunities)FROM Account]){
oppMap.put(acc.Name,acc.Opportunities);
}
}
}
///VF
<apex:page controller="Map_Opportunities">
<apex:form >
<apex:pageBlock title="Account Map">
<apex:pageBlockButtons location="Bottom" style="opportunity">
</apex:pageBlockButtons>
<apex:pageBlockSection columns="1" collapsible="false" >
<apex:pageBlockTable value="{!oppMap}" var="m">
<apex:column value="{!m}" headerValue="Account Name"/>
<apex:column value="{!oppMap[m]}" headerValue="Opportunity Name"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public class Map_Opportunities {
public Map<string,List<Opportunity>> oppMap {set;get;}
public List<Opportunity> optyList {set;get;}
public Map_Opportunities(){
oppMap = new Map<string,List<Opportunity>>();
for (Account acc: [SELECT name,(SELECT Name FROM Opportunities)FROM Account]){
oppMap.put(acc.Name,acc.Opportunities);
}
}
}
///VF
<apex:page controller="Map_Opportunities">
<apex:form >
<apex:pageBlock title="Account Map">
<apex:pageBlockButtons location="Bottom" style="opportunity">
</apex:pageBlockButtons>
<apex:pageBlockSection columns="1" collapsible="false" >
<apex:pageBlockTable value="{!oppMap}" var="m">
<apex:column value="{!m}" headerValue="Account Name"/>
<apex:column value="{!oppMap[m]}" headerValue="Opportunity Name"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Let us know if this will help you
All Answers
https://sfdcknowledgebank.wordpress.com/2013/08/19/displaying-a-map-in-visual-force-page/
Let us know if this will help you