Thursday, August 14, 2014

How to open child records list from custom button on parent object?

Hi,

In this post i am giving an example of how to display contact records in a VF page when we click on custom button on Accounts page. Once we click on Custom page it will call Visualforce page and display related contacts for the Account.

Step1:

Goto Setup-->Customize-->Account--> Buttons Links and Actions-->Click on New Button Or Link-->Create a button with Label and Enter the code in Script Area.

Develop a visualforce page with Custom controller and save it. here the page name should be same as in the button script. in my custom button script i gave the url as "/apex/ShowContactsForAccountVF?acId={!Account.Id}", So My page name should be ShowContactsForAccountVF.

Visualforce Page :

<apex:page controller="ShowContactsForAccountCLS">

<apex:pageBlock >

<apex:pageblockTable value="{!contactList}" var="cl">

<apex:column value="{!cl.FirstName}"/>

<apex:column value="{!cl.LastName}"/>

<apex:column value="{!cl.Phone}"/>

<apex:column value="{!cl.Email}"/>

</apex:pageblockTable>

</apex:pageBlock>

</apex:page>

Output : once you click on "Show Contacts" on Account Detail page it will open the contact details like this.