The <apex:detail>
component is used to display the detailed view of a Salesforce record on a Visualforce page. It replicates the standard layout of a record, similar to what users see in the Salesforce UI.
Why Use <apex:detail>
?
- Easily show the full details of a Salesforce record.
- Leverage standard page layouts without custom code.
- Integrates seamlessly with Salesforce record data.
Basic Syntax
xmlCopyEdit<apex:detail subject="{!recordId}" relatedList="true" title="true"/>
subject
: The ID of the record you want to display.relatedList
: Iftrue
, shows related lists (like Contacts under Account).title
: Iftrue
, displays the standard record title at the top.
Example: Displaying Account Record Details
xmlCopyEdit<apex:page standardController="Account">
<apex:detail relatedList="true" title="true"/>
</apex:page>
This code uses a standard controller for the Account object and displays the account’s full details.
Key Attributes
relatedList
: Shows related lists if set totrue
.title
: Displays the record title/header when set totrue
.showChatter
: Set totrue
to include the Chatter feed for the record (if enabled).inlineEdit
: Allows inline editing of fields when enabled.
Use Cases
- View-Only Record Page: When you need a read-only view of a record.
- Custom Record Pages: Integrate into a custom layout with other components.
- Detail View with Related Lists: Show contacts, opportunities, or other related records.