Sunday, January 25, 2015

How to Use Apex:relatedList tag in Visualforce Page?

How to Use Apex:relatedList tag in Visualforce Page?


It is going to display a list of Salesforce records that are related to a parent record with a lookup or master-detail relationship.


This tag supports following attributes.

Attribute Name
Description
id
An identifier that allows the relatedList component to be referenced by other components in the page.
list
The related list to display. This does not need to be on an object's page layout. To specify this value, use the name of the child relationship to the related object. For example, to display the Contacts related list that would normally display on an account detail page, use list="Contacts".

pageSize
The number of records to display by default in the related list. If not specified, this value defaults to 5.
rendered
A Boolean value that specifies whether the component is rendered on the page. If not specified, this value defaults to true.
subject
The parent record from which the data and related list definition are derived. If not specified, and if using a standard controller, this value is automatically set to the value of the ID query string parameter in the page URL.
title
The text displayed as the title of the related list. If not specified, this value defaults to the title specified in the application.


Facet Name
Description
body
The components that appear in the body of the related list. Note that the order in which a body facet appears in a relatedList component does not matter, because any facet with name="body" will control the appearance of the related list body. If specified, this facet overrides any other content in the related list tag.
footer
The components that appear in the footer area of the related list. Note that the order in which a footer facet appears in the body of a relatedList component does not matter, because any facet with name="footer" will control the appearance of the bottom of the related list.
header
The components that appear in the header area of the related list. Note that the order in which a header facet appears in the body of a relatedList component does not matter, because any facet with name="header" will control the appearance of the top of the related list.



Example :

<apex:page standardController="Account">
    <apex:pageBlock >
    You're looking at some related lists for {!account.name}:
    </apex:pageBlock>

    <apex:relatedList list="Opportunities" />

    <apex:relatedList list="Contacts">
        <apex:facet name="header">Titles can be overriden with facets</apex:facet>
    </apex:relatedList>

    <apex:relatedList list="Cases" title="Or you can keep the image, but change the text" />
</apex:page>


Pass the account id as url parameter to display the related list.
For example, if 001D000000IRt53 is the account ID, the resulting URL should be:
https://Salesforce_instance/apex/myPage?id=001D000000IRt53






More about Visualforce Tags Examples:

0 comments:

Post a Comment

 
| ,