Play Games

Search This Blog

Wednesday, April 29, 2015

How to access map values in visualforce page

step 1) Create apex controller as shown below.

public class mapcontroller {
 
    public Map<id,contact> conmap{get;set;}
 
    public  mapcontroller(){
        conmap=new Map<id,contact>();
        for(contact con:[select id,name from contact]){
            conmap.put(con.Id,con);
        }
    }
 
}



step 2) Create a visualforce page as shown below.

<apex:page controller="mapcontroller">
<apex:form >
<apex:pageBlock >
<apex:repeat value="{!conmap}" var="con">
       {!con}<br/><br/>
         <apex:repeat value="{!conmap[con]}" var="con1">
        {!con1.name} <br/><br/>
         </apex:repeat>

    </apex:repeat>
</apex:pageBlock>
  </apex:form>
</apex:page>

step 3) Run the visualforce page you will get output as shown below.

output:
0039000000JplT1AAJ

ram mohan 

0039000000JptmvAAB

swetha mohan 

0039000000JqYsUAAV

Sachin tendulkar 

0039000000Jqv2RAAR


Enjoy Coding...