• Abhishek Mahajan 26
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
i am trying as below : (CLASS)
public class Displaycontactbyaccname {
   public Map <string,List<Contact>> contactMap {get;set;}
public Displaycontactbyaccname() {
      contactMap = new Map < string, List < Contact >> ();
        List<Contact> conlist = [Select LastName,Account.Name from Contact Where Account.Name != null ];
        System.debug('conn'+conlist[0].Account.Name);
         for (Contact con : conlist)
       {
          if(contactMap.containskey(con.account.Name))
          contactMap.get(con.account.Name).add(con);
      else
          contactMap.put(con.account.Name,new list<contact>{con});
               } }}


and below VF page is 
<apex:page controller="Displaycontactbyaccname">
 <apex:form >
 <apex:pageBlock >
  <apex:pageBlockTable value="{!contactMap}" var="item"  >
    <apex:column value="{!item}"/>  <!-- key --->
    <apex:column value="{!contactMap[item]}"/>  <!-- Value--->
</apex:pageBlockTable>
</apex:pageBlock>
 </apex:form>
</apex:page>


But output is not right : please help me 
thanks in advance :))