function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
Try this code:-
Page:-
<apex:page controller="createMap">
<apex:form id="formId">
<apex:pageBlock id="pgBlockId">
<apex:pageBlockTable value="{!namePhoneMap}" var="item" >
<apex:column value="{!item}"/> <!-- key --->
<apex:column value="{!namePhoneMap[item]}"/> <!-- Value--->
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Class:-
public class createMap{
public Map<String,String> namePhoneMap{get;set;}
public List<Account> accList{get;set;}
public createMap(){
accList = new List<Account>();
namePhoneMap = new Map<String,String>();
accList = [select id,name,phone from Account limit 10];
if(accList != null && accList.size() > 0){
for(Account acc : accList ){
namePhoneMap.put(acc.name,acc.phone);
}
}
}
}
Output:-
Let me know in case of any concerns.
Please mark this answer as the solution/ best answer if it solves your purpose so that it can help other community members.
Thanks,
Pramod Nishane
Salesforce Consultant
Varasi LLC
www.varasi.com
All Answers
You need to create a map like below:
public static Map<String, Integer> studentMap = new Map<String, Integer>{
'John' => 9866565656,
'Sara' => 9866565658,
'Ron' => 9861569552,
'Harry' => 9861519552,
};
You have to use apex:repeat tag as below:
Visualforce code goes like:
<apex:repeat value="{!studentMap }" var="key">
<apex:column headerValue="{!key}"/> <!-- key --->
<apex:column value="{!studentMap [key]}"/> <!-- Value--->
</apex:repeat>
Thanks.
Try this code:-
Page:-
<apex:page controller="createMap">
<apex:form id="formId">
<apex:pageBlock id="pgBlockId">
<apex:pageBlockTable value="{!namePhoneMap}" var="item" >
<apex:column value="{!item}"/> <!-- key --->
<apex:column value="{!namePhoneMap[item]}"/> <!-- Value--->
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Class:-
public class createMap{
public Map<String,String> namePhoneMap{get;set;}
public List<Account> accList{get;set;}
public createMap(){
accList = new List<Account>();
namePhoneMap = new Map<String,String>();
accList = [select id,name,phone from Account limit 10];
if(accList != null && accList.size() > 0){
for(Account acc : accList ){
namePhoneMap.put(acc.name,acc.phone);
}
}
}
}
Output:-
Let me know in case of any concerns.
Please mark this answer as the solution/ best answer if it solves your purpose so that it can help other community members.
Thanks,
Pramod Nishane
Salesforce Consultant
Varasi LLC
www.varasi.com