apex:detail Component
The apex:detail
component is a Visualforce component used to display a detailed view of a single Salesforce record. It automatically generates a page layout that displays fields, related lists, and buttons for a given record.
Syntax
The syntax for the apex:detail
component is as follows:
<apex:detail subject="{!recordId}" relatedList="true">
Example
Consider the following example in which we want to display the detailed view of an Account record:
<apex:page standardController="Account" recordSetVar="accounts">
<apex:pageBlock >
<apex:pageBlockTable value="{!accounts}" var="a">
<apex:column >
<apex:facet name="header">Name</apex:facet>
<apex:outputText value="{!a.name}"/>
</apex:column>
<apex:column >
<apex:facet name="header">View Details</apex:facet>
<apex:detail subject="{!a.id}" relatedList="true"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
In this example, we are using the apex:detail
component within a Visualforce page to display the detailed view of each Account record displayed in a page block table.
Explanation
The apex:detail
component is used to display a detailed view of a single Salesforce record. It can be used to display fields, related lists, and buttons for the given record.
In the above example, we are using it to display the related lists for an Account record. We are passing in the record Id of the Account record to display its related lists along with the standardController attribute on the page.
Use
The apex:detail
component can be used to quickly and easily display the detailed view of a Salesforce record, including all its related objects. It is particularly useful when building custom Visualforce pages that display data to users.
Important Points
- The
apex:detail
component requires the standardController attribute on the page to retrieve record Id. - The component can only display the detailed view of one record at a time.
- Use the
relatedList
attribute to control the display of related lists.
Summary
The apex:detail
component is a Visualforce component used to display a detailed view of a Salesforce record, including fields, related lists, and buttons. It is useful for quickly displaying details about a record in a custom Visualforce page without having to customize the page layout. The component requires the standardController attribute on the page to retrieve record Id and can only display one record at a time.