While working as a Salesforce Admin, I received a requirement from the client who sells home automation products. They wanted their support team to quickly access the installation video for every product that a customer purchases.
For example, when a customer buys a product like Wi-Fi or a camera, the support team should see a clickable “Watch Installation Video” link directly on the product record in Salesforce.
The client didn’t want long URLs to appear on the screen. They wanted a short link that opens the video in a new tab.
To solve this, I used the HYPERLINK() function in a formula field in Salesforce. This function allowed me to show a text link instead of the full video URL.
In this article, we will learn how to use the HYPERLINK() Function in Salesforce. Additionally, we will examine the syntax and provide some real-world examples of the function.
What is the HYPERLINK() Function in Salesforce?
HYPERLINK() Function in Salesforce is one of the available TEXT functions in Salesforce, which is used to perform text operations on the fields in Salesforce. This HYPERLINK() function in Salesforce is used to create clickable links in the formula fields.
We can use a URL-specified link that can be linked from the specified text to redirect to various destinations, such as external websites, documents, records, images, videos, or a direct phone dialer.
And, the syntax of the Salesforce HYPERLINK Function is given below:
HYPERLINK(url, friendly_name [,target])
Here is a detailed description of the parameters:
- URL: The URL parameter specifies the destination URL, or you can say the web address to which the hyperlink points.
- friendly_name: The friendly_name parameter specifies the text, or you can say the link text, that you want to display as the clickable link.
- target: The target parameter specifies the window, or you can say frame, in which you want to display the content that you get on the click of the link. This parameter is optional; if you don’t want to use it, the hyperlink opens in a new browser window or tab. Some of the common target parameters that you can use are as follows:
- _blank: This _blank target parameter is used to display the link in the new unnamed window.
- _parent: This _parent target parameter points to the link in the immediate parent frameset of the current frame. If the current frame has no parents, this value is the same as _self.
- _self: This _self target parameter is used when displaying the link content in the same frame or window.
- _top: This _top target parameter is used to display the link in the full window and cancel out the other frames. If the current frame has no parents, this value is the same as _self.
Moreover, there are some considerations that we must keep in mind while using the Salesforce HYPERLINK Function:
- TEXT Field Type: In Salesforce, the HYPERLINK formula fields are of the “Text” data type. This means that the result of the HYPERLINK formula field is in text format.
- Use Quotation Marks: While defining the hyperlink in Salesforce, enclose both the protocol and the URL in double quotes—for example, HYPERLINK(“https://www.salesforcefaqs.com”, “Visit your Salesforce Website”).
- Don’t Use Other Text Functions: Avoid using the other Salesforce text functions, such as “LEN“, “LEFT”, or “RIGHT”, on the HYPERLINK function, as it affects the result of the hyperlink function.
- Don’t Use JavaScript in the URL: Never use JavaScript in the URL of a hyperlink, as it can compromise your organisation’s security. However, you can use JavaScript in specific contexts, such as packages, sandbox copies, and change sets.
- $Api Variable for API URLs: In Salesforce HYPERLINK, use the $Api variable to reference API URLs.
- Remove Brackets: Before validating the formula, ensure that you remove the square brackets [] from the formula.
- Use Relative Links: