+ Start a Discussion

Visual force page dynamically showing related contacts of an account

I have a vf page listing accounts,on clicking on the account name field(link), account related contacts should be displayed dynamically.I am trying to pass the account value (clicked) from page to controller but in the debug logs I see value its null.


Hi s_mac,

The below solution might help you out :

Visual Force Page Code:
// Here standardController=”account” used to display account details dynamically.
<apex:page standardController="Account" recordSetVar="accounts" tabstyle="account" sidebar="false" extensions="DisplayContact" >
  <apex:pageBlock title="Account" >
    <apex:form >
      // Here your account details is shown using standard  controller.
      <apex:pageBlockTable value="{!accounts}" var="a" id="list">
        <apex:column headerValue="Account Name">
// Here is the account name display, when you click on the name of the account then it will get the Id and display the contact under the account list
        <apex:commandLink rerender="contactDetails" value=" {!a.Name}" action="{!ContactLists}">
// Getting the account id that retrive the contact details
         <apex:param name="id" value="{!a.id}"/>
        <apex:column value="{!a.type}" />
        <apex:column value="{!a.billingstreet}"/>
        <apex:column value="{!a.billingCity}" />
        <apex:column value="{!a.billingCountry}" />
        <apex:column value="{!a.billingPostalCode}"/>
  <apex:pageBlock title="Contact">
   <apex:outputPanel id="contactDetails">
// Display contact list according to their Account Id.
     <apex:pageBlockTable value="{!conList}" var="con" id="conlist" title="Contact">
     <apex:column value="{!con.Name}"/>
     <apex:Column value="{!con.Phone}" />
     <apex:Column value="{!con.Email}" />
Apex Class:

public with sharing class DisplayContact {
    public List<Contact> conList {get;set;}
    public DisplayContact(ApexPages.StandardSetController controller) {

    public PageReference ContactLists()
// Checking account id is not null.
    if(ApexPages.currentPage().getParameters().get('id') != null)
      conList = [Select id,Name,Phone,Email from contact where accountId =: ApexPages.currentPage().getParameters().get('id')];
     return null;



Here is the Account Details

User-added image

When you click on Account Name then you will show related Contact here

User-added image

Hope This will help you.
If this answers your query please mark this question as a solved so that it can be filtered out from unsolved questions.