The <apex:outputLink> component is used to create a standard HTML link that navigates to a specified URL or page. It does not invoke controller actions like <apex:commandLink> does.
Syntax
xmlCopyEdit<apex:outputLink value="/apex/AccountDetails">Go to Account Details</apex:outputLink>
Key Attributes
| Attribute | Description |
|---|---|
value | URL of the page to navigate to. |
target | Optional. Specifies where to open the linked document (e.g., _blank, _self). |
styleClass | Optional. CSS class for styling. |
Example 1: Basic Navigation Link
xmlCopyEdit<apex:outputLink value="/apex/AccountPage">View Account</apex:outputLink>
- Redirects to the
AccountPagewhen clicked.
Example 2: Link With Dynamic Parameters
xmlCopyEdit<apex:outputLink value="/apex/AccountPage?id={!account.Id}">
{!account.Name}
</apex:outputLink>
- Dynamically passes the
account.Idin the URL.
Example 3: Open Link in New Tab
xmlCopyEdit<apex:outputLink value="https://www.salesforce.com" target="_blank">
Visit Salesforce
</apex:outputLink>
- Opens the Salesforce homepage in a new browser tab.
When to Use <apex:outputLink>
- To navigate to another Visualforce page or external URL.
- When you don’t need to invoke Apex controller logic.
- Best for static or dynamic navigation based on record data.
Best Practices
- Use it for simple redirection needs.
- Combine with expressions like
{!record.Id}for dynamic URLs. - Use
target="_blank"when linking to external websites.