In this tutorial, I am going to show you an example of a relatedList component in Visualforce Page. The related list component allows you to display related records based upon a lookup or master-detail relationship.

How to display Related List in Visualforce Page:

The tag-based syntax provided in the visualforce page allows you to design User Interface more effectively and with very little effort. One of the most powerful components provided is apex:relatedList which allows you to display related records based upon a lookup or master-detail relationship. One of the most important benefits of using the Related List tag that any change you make to the related list in the page layout editor (columns, sorting, etc.) will automatically be reflected in your Visualforce page.

Example:

Suppose I want to display List of Contact, Opportunity, and Case on a visualforce page related to account we can easily done with this with Related List component.

Create a Visualforce called relatedListDemo. Replace the following markup with the existing one.

<apex:page standardController="Account">
 <apex:pageBlock>
Related lists for {!account.name}:
 </apex:pageBlock>

<apex:relatedList list="Opportunities" />

<apex:relatedList list="Contacts">
 </apex:relatedList>

<apex:relatedList list="Cases" title="Cases" />
</apex:page>

Preview the Visualforce Page with the following URL

apex/relatedListDemo?id=Account-Id

Where Account-Id is salesforce Account ID.

Related List

View More:

Conclusion:

I hope you would love this post. Please feel free to comment for any technical help. Your feedback and suggestions would be helpful for me.

Thank You.

Leave a Comment