salesforce
  1. salesforce-apex-outputlink-component

apex:outputLink Component

The apex:outputLink component is a part of Visualforce in Salesforce that is used to output a hyperlink to a web page, record detail page, or other web-based resource. It is a powerful component that allows you to create clickable links that take users to different destinations based on the values you specify.

Syntax

The syntax for using apex:outputLink is as follows:

<apex:outputLink value="{!url}" target="{!window}" rendered="{!condition}">
    Link Text Here
</apex:outputLink>

Example

Consider the following example:

<apex:outputLink value="{!$Page.MyCustomPage}" target="_blank">
    Go to My Custom Page
</apex:outputLink>

In this example, when a user clicks on the link "Go to My Custom Page", they will be taken to the web-based resource specified by the value attribute, which in this case is a custom Visualforce page named "MyCustomPage". The target attribute specifies that the page should be opened in a new tab or window.

Output

The output of the above code will be a clickable link that says "Go to My Custom Page".

Explanation

The apex:outputLink component generates an HTML anchor tag that can be clicked to take the user to a specified URL. The value attribute specifies the URL that the link will navigate to The target attribute specifies where to open the link - in a new window, tab, or in the same window. The rendered attribute is used to control whether the link is displayed or not based on a condition.

Use

The apex:outputLink component is commonly used to create hyperlinks for navigating to external web pages, pages within the same Salesforce org, or record detail pages. It can be used in conjunction with controller methods to generate URLs dynamically, and can be styled using CSS to match the look and feel of your application.

Important Points

  • When using the value attribute, make sure that the URL is properly formatted with the http:// or https:// protocol prefix.
  • The target attribute can be set to _blank to open the link in a new window or tab, or to _ to open the link in the same window or tab.
  • The rendered attribute can be used to hide the link based on a condition.

Summary

The apex:outputLink component is a powerful tool in Visualforce that allows you to create clickable links that take users to different destinations. It is commonly used to create hyperlinks for navigating to external web pages, pages within the same Salesforce org, or record detail pages. The value attribute specifies the URL that the link will navigate to, and the target attribute specifies where to open the link. The rendered attribute can be used to control whether the link is displayed or not based on a condition.

Published on: