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:commandLink>
</apex:column>
<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:pageBlockTable>
</apex:form>
</apex:pageBlock>
<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:pageBlockTable>
</apex:outputPanel>
</apex:pageBlock>
</apex:page>
Screenshot:Here is the Account DetailsApex 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;
}
}
When you click on Account Name then you will show related Contact here
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.Regards,Akshay
1 answer