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
Venkateswarlu PVenkateswarlu P 

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>
 
Best Answer chosen by Venkateswarlu P
Amit Chaudhary 8Amit Chaudhary 8
Update your VF page like below
<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 headerValue="Opportunity Name">
                        <apex:pageBlockTable value="{!oppMap[m]}" var="m">
                            <apex:column value="{!m.name}" headerValue="Opp Name"/>
                        </apex:pageBlockTable>                
                    </apex:column>
                    
                </apex:pageBlockTable>                
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Let us know if this will help you
 

All Answers

SFDC RohitSFDC Rohit
Here is the best example of map:
https://sfdcknowledgebank.wordpress.com/2013/08/19/displaying-a-map-in-visual-force-page/
Amit Chaudhary 8Amit Chaudhary 8
Update your VF page like below
<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 headerValue="Opportunity Name">
                        <apex:pageBlockTable value="{!oppMap[m]}" var="m">
                            <apex:column value="{!m.name}" headerValue="Opp Name"/>
                        </apex:pageBlockTable>                
                    </apex:column>
                    
                </apex:pageBlockTable>                
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Let us know if this will help you
 
This was selected as the best answer
Venkateswarlu PVenkateswarlu P
Thank you