HYPERLINK() Function in Salesforce [Syntax, Examples, & Use Cases]

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:

  1. 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.
  2. 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”).
  3. 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.
  4. 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.
  5. $Api Variable for API URLs: In Salesforce HYPERLINK, use the $Api variable to reference API URLs.
  6. Remove Brackets: Before validating the formula, ensure that you remove the square brackets [] from the formula.
  7. Use Relative Links: To link to the Salesforce page, use a relative link rather than the full URL. The portion of the URL after the domain is called the relative link. Also, ensure you include the forward slash (/) in the relative URL so it works on all Salesforce pages.
  8. Chatter Feed Target Parameter: The target argument in Chatter feed links is not rendered and defaults to _blank.
  9. Use HYPERLINK Function: You can use the HYPERLINK function everywhere in Salesforce except for default values, field updates, s-controls, validation rules, approval processes, custom buttons and links, and workflow rules.

Now, let’s move ahead and learn to use the HYPERLINK() Function in Salesforce.

Use HYPERLINK() Function in Salesforce

Here, we will learn to use the HYPERLINK function in Salesforce to create a hyperlink. Let’s consider a scenario to better understand the concept of a function.

Suppose you work in a sales company and want to survey multiple people to gather customer feedback about the services they received.

So, the following are the steps to use the HYPERLINK function in Salesforce for the above-defined scenario:

  1. Log in to Salesforce, click on the “Gear” icon at the top right side of the page, and then click on the “Setup” (Setup for current app) option from the dropdown.
HYPERLINK Function in Salesforce
  1. Once you land on the setup for the current app in Lightning, you will see an “Object Manager” option. Click on it.
HYPERLINK Function in Salesforce Example
  1. Now, search for the object in which you want to use the HYPERLINK function in “Quick Find Search”. As per the scenario, I need to survey all customers. I searched for the “Contact” object and clicked on it.
HYPERLINK Function in Salesforce Lightning
  1. On the product object page, the Field & Relationship option is in the details section on the left side. Select “Field & Relationship” from the menu.
    • The field and relationships page is opened after selecting the field and relationship option. Click the “New” button at the top of the page.
HYPERLINK Function in Salesforce Lightning Example
  1. Once you click New, you will see a list of all field types in Salesforce. Select the one from the list that you need. 
    • But since your objective is to use the HYPERLINK function, you need the “Formula” field type. So, I have selected the “Formula” field type. Then, click on the “Next” button to move to the next page.
Salesforce HYPERLINK Function
  1. In this step, enter the “Field Label” and “Field Name” first. As per the scenario, I entered the field label “Survey Link,” and when I click the field name box, the field name automatically populates.
    • Now, scroll down and choose the data type for the field in which you will get the result. Here, I select the Text data type because we have learned that HYPERLINK formula fields are of the “Text” data type.
    • So, I check the “Text” data type radio button and set the formula’s return value to text format.
    • After that, click on the“Next” button to proceed to the next step.
Salesforce HYPERLINK Function Example
  1. Once you click next, you will be taken to the add formula page. Move to the right side of the page, here you will get the “Functions Section” and here is the dropdown field “All Function Categories”, click on it, and from here choose “Text”.
  • Once you click on the Text, you will get the list of the functions that are in the text categories. Now, from here, you have to choose the “HYPERLINK” function and enter it into the advanced formula editor, as today’s topic is to understand how to use the HYPERLINK function.
    • Now, let’s create a formula as per our above-defined scenario:
HYPERLINK("https://forms.gle/Msxjhgn_ghsbjd", "Take Survey")

Here:

  • We use the Salesforce HYPERLINK() function that creates a clickable hyperlink.
  • Next, we pass the Google Form URL “https://forms.gle/Msxjhgn_ghsbjd” to link to the survey.
  • After that, we pass the text “Take Survey” which will be displayed as a hyperlink. When the customer clicks the text, they will be redirected to the Google Form URL we provided.
  1. Scroll down and click on the “Check Syntax” button, and verify whether the formula is correct or has some errors. Optionally, you can also define the “Description”“Help Text”, and “Handle the empty field”. After that, click on the “Next” button to move to the next step.
Salesforce Lightning HYPERLINK Function
  1. In this step, establish Field-Level Security. Now choose the profiles to which we wish to grant field-level security edit access to this field. If field-level security is not added, the field will be hidden from all profiles.
    • As I want it to be visible to all profiles, I have chosen “Visible” in this instance. After that, click the “Next” button located at the top.
Salesforce Lightning HYPERLINK Function Example
  1. Add the custom field to the Page Layout after setting up the field-level security. Pick the page layout that has this field in it. If we do not select a layout, the field will not appear on any pages.
    • To save the formula field, click the “Save” button.
How to use the HYPERLINK function in Salesforce Lightning

Once you have created the formula field, you can use it. Let’s look at an example:

  • Open the Contacts items, create a new contact, and save it.
  • Once you save the contact, you will move to the Detail Section, where you will get the field “Survey Link” with the hyperlink.
HYPERLINK() Function in Salesforce | Syntax, Examples, & Use Cases

In this way, we can use the HYPERLINK() function in Salesforce to create clean, clickable links that help users open important pages, documents, and videos.

Conclusion

With this, we have learned that the HYPERLINK function of Salesforce is used to create clickable links. We have also learned the syntax and various business-related examples of the HYPERLINK function.

In addition, we learned the step-by-step process for using the HYPERLINK function in Salesforce.

You may like to read the following articles:

Agentforce in Salesforce

DOWNLOAD FREE AGENTFORCE EBOOK

Start with AgentForce in Salesforce. Create your first agent and deploy to your Salesforce Org.

Salesforce flows complete guide

FREE SALESFORCE FLOW EBOOK

Learn how to work with flows in Salesforce with 5 different real time examples.