You need to sign in to do that
Don't have an account?
Rahul Chauhan 33
i want to make make VF page where i have to display all accounts with their contacts . Query must on contact.
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 :))
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 :))
thanks in advance :)))))
Here is my code which you can refer, i have tested it in my org and it is working fine.
Visualforce Page:
Controller: If the number of records are more then you will have to implement pagination.
Hope it helps!
Please mark as complete is it solves the Purpose.
Thanks! :)
My requirement is to display as follow
Account Name
Contact 1
contact 2
Account Name 2
Contact3
contact4
-------
i want output in multiple row single column...??
Finally after so much of research, i have found a way to meet your requirement. Please check if it solves your purpose.
Visualforce:
Controller:
I hope this will help! :)