HYPERLINK() Function in Salesforce

In this Salesforce tutorial, we will learn how to use the HYPERLINK() Function in Salesforce. In addition, we will see the syntax and some real-world examples of the function.

While working as a Salesforce developer, in the Phoenix Customer Management Company. I got a task to attach the link to the installation video of the products.

As a solution, I found that Salesforce provides us the function named “HYPERLINK” using which we can add a link. If you want to learn how to add the link using the Salesforce HYPERLINK function with multiple examples go through the complete article.

Salesforce HYPERLINK function

HYPERLINK() Function in Salesforce is one of the available TEXT functions in Salesforce which is used to perform the 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 this URL-specified link that is linkable from the text specified to redirect to various destinations like external websites, documents, records, images, videos, direct phone dialer, etc.

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 whom 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 the new browser window or tab. Some of the common target parameters that you can use are as below:
    • _blank: This _blank target parameter, is used to display the link in the new unnamed window.
    • _parent: This _parent target parameter, displays the link in the immediate frameset parent 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 your mind while using the Salesforce HYPERLINK Function:

  1. TEXT Field Type: In Salesforce, the HYPERLINK formula fields are of the “Text” data type. It means that the result value of the HYPERLINK formula field is in a text format.
  2. Use Quotation Marks: While defining the hyperlink in the Salesforce, enclose both protocol and URL in the 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 function 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 hyperlink URL because Javascript affects the security of your org. But, you can use JavaScript in certain contexts like 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, make sure to remove the square brackets [] from the formula.
  7. Use Relative Links: To link to the salesforce page, use the relative link instead of the full URLs. The portion of the URL that comes after the domain, is called the relative link. Also, make sure to include the forward slash / with the relative URL so that it works on all the Salesforce pages.
  8. Chatter Feed Target Parameter: The target argument in Chatter feed links does not render, and is set to _blank by default.
  9. Use HYPERLINK Function Except: 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.

Let’s see an example of the HYPERLINK Function to understand the topic better:

Suppose, you are working as a marketing assistant in a company that uses Salesforce as a tool, and you got a task to attach a link of the document that contains the information about the opportunity and the document required by the marketing team.

So for this, you can use the HYPERLINK Function of Salesforce that attaches the link of the document stored in Google Drive. And, here is the formula:

HYPERLINK("https://www.googledrive.com/opportunity_documnet", "Open your Opportunity Document")

With this, we have learned about the HYPERLINK function of Salesforce with syntax and various important considerations. Moreover, we have seen a small example related to the function for a deep understanding of the topic.

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

Read IMAGE() Function in Salesforce

How to use the HYPERLINK function in Salesforce Lightning

Here, we will learn to use the HYPERLINK function in Salesforce Lightning to create a hyperlink. Let’s take a situation to better understand the idea of the function.

Suppose you are working in a sales company and want to do a survey of multiple people to get the feedback of the customer regarding the services they provided.

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

Step 1: Login to the Salesforce account lightning experience. If you are not on the main home setup page of lightning experience, 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

Step 2: Once you land on the setup for the current app in Lightning, you will get an option of the “Object Manager” in the navigation bar adjacent to the home tab. Click on it.

HYPERLINK Function in Salesforce Example

Step 3: On the object manager page, you will get the list of all the custom and standard objects of Salesforce. 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 take a survey of all the customers, I searched for the “Contact” object and click on it.

HYPERLINK Function in Salesforce Lightning

Step 4: After you click on the contact, you will get the option of “Fields & Relationship” on the left side of the page, click on it. Now, you will see all the items sorted by the field label, but here you have to create a new field so that you can use the HYPERLINK function and create a formula, so click on the “New” button.

HYPERLINK Function in Salesforce Lightning Example

Step 5: Once you click on new, you will get the list of all the field types in Salesforce select the one from the list that you needed. But as your objective is to use the HYPERLINK function, you need the “Formula” field type for this. So, I have selected the “Formula” field type. Then, click on the “Next” button, to move to the next page.

Salesforce HYPERLINK Function

Step 6: In this step, first enter the “Field Label” and “Field Name”. As per the scenario, I entered the field label “Survey Link” and as I click on the field name box the field name automatically get populated.

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 radio button next to the “Text” data type and set the return value of the formula in the text format.

After that, click on the “Next” button to proceed to the next step.

Salesforce HYPERLINK Function Example

Step 7: Once you click on the next, you will be landed on 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 advance formula editor as our today 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 form hosted by Google Form as a URL “https://forms.gle/Msxjhgn_ghsbjd” that we want to link to the survey.
  • After that, we pass the text “Take Survey” which will be displayed as the hyperlink. When the customer clicks on the text, they will be redirected to the Google Form URL that we have provided.

Step 8: 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”, and “Help Text” as well as “Handle the empty field”. After that, click on the “Next” button to move to the next step.

Salesforce Lightning HYPERLINK Function

Step 9: Once you click on the next button, you will be redirected to the “Field Level Security” page. From here choose the user profiles to whom you want to grant the field-level security edit access to the field. If not added the field level security, the custom formula field that we have created not shows on the unselected profile.

In my example, I check the checkbox next to the “Visible” option as I want to visible this custom field for all the profiles. After that click on the “Next” button and move to the next step.

Salesforce Lightning HYPERLINK Function Example

Step 10: In this step, choose the “Page Layout” where you want to add the custom formula field. If you do not select a layout, the field will not appear on any pages. And last, to save the advanced formula field, click on the “Save” button.

How to use the HYPERLINK function in Salesforce Lightning

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

  • Open the Contacts items and create a new contact and save it.
  • Once you save the contact you will move to the Detail Section, here you will get the field “Survey Link” with the hyperlink of the link.
How to use the HYPERLINK function in Salesforce Lightning Example

With this, we have learned how to use the HYPERLINK function in Salesforce Lightning. Next, we will move ahead and learn to use the HYPERLINK function in Salesforce Classic.

Read INCLUDES() Function in Salesforce

How to use the HYPERLINK function in Salesforce Classic

Here, we will learn to use the HYPERLINK function in Salesforce Classic to create a hyperlink. Let’s take a situation to better understand the idea of the function.

Suppose, you are working as an HR of the company and you got a task to add up the link of the product user manual to provide support to the customer with quick information. So, for this, we will use the HYPERLINK function of Salesforce.

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

Step 1: First, login to the Salesforce account in Classic Experience. If you are not logged in to the classic, click on the “Avatar” and then click on the option “Switch to Salesforce Classic” from the dropdown.

HYPERLINK Function in Salesforce Classic

Step 2: Once you are successfully logged in to the Salesforce Classic, click on the “Setup” option at the top right side of the page between your name and the help option.

HYPERLINK Function in Salesforce Classic Example

Step 3: After landing on the setup page, move downward to the “Build” section, click on the “Customize” dropdown, and choose the object from the list of the Salesforce objects on which you want to use the HYPERLINK function. As per the above-defined scenario, I searched and select the “Product” object.

As you click on the product object dropdown, you will get multiple options related to the product object. From here I choose the “Fields” option as our requirement is to create a field where you can use the Salesforce Function.

Salesforce Classic HYPERLINK Function

Step 4: Once you clicked on the field option, the product field page gets opened, move downward to the “Product Custom Fields & Relationship” section and click on the “New” button to create a new custom field in Salesforce.

Salesforce Classic HYPERLINK Function Example

Step 5: After you click on the new button, you will get all the field types in Salesforce, choose the as per your requirement. In our case, we need the “Formula” field type as we mention in the scenario we are going to create a formula where we will use the function. So, I click on the radio button next to the “Formula” field type and select them.

And after that, click on the “Next” button at the top to move to the next step.

How to use the HYPERLINK function in Salesforce Classic

Step 6: You are on the “Choose Output Type” page. Enter the “Field Label” and “Field Name” field details. Here, I enter the field label as “Product Manual” and when I click on the field name box it gets automatically filled up.

Scroll down and set the formula return type for the field that we have created. Here, I select “Text” as the data type because we know that the HYPERLINK function always returns the output in the text format. If you try to use any other data type as a return type you will get an error.

After that, click on the “Next” button to move to the next step.

How to use the HYPERLINK function in Salesforce Classic Example

Step 7: You will get to the add formula screen after clicking next. Go to the “Functions Section” on the right side of the page, where you will find a drop-down box labeled “All Function Categories”. Click this dropdown to access the “Text” option.

As the present topic is to learn how to apply the HYPERLINK function, you must select the “HYPERLINK” function from the list of functions that are in the text categories and enter it into the advance formula editor.

Let’s now develop a formula based on the scenario we mentioned above:

HYPERLINK("https://www.tsinfo.com/iphone15_techproducts_manual.pdf", "Open Product Manual")

Here:

  • We use the Salesforce HYPERLINK() function that creates a clickable hyperlink.
  • Next, we pass the URL “https://www.tsinfo.com/iphone15_techproducts_manual.pdf” of the PDF product manual that we want to link to the product manual.
  • After that, we pass the text “Open Product Manual” which will be displayed as the hyperlink. When the customer clicks on the text, they will be redirected to the PDF manual URL that we have provided.

Step 8: Click the “Check Syntax” button under the advanced formula editor to confirm that the formula you just enter is free of errors. You will get the message “No syntax errors in merge fields or function” if there are no errors. However, you will see an error notification on the screen if there is an error.

Define the “Description” and “Help Text” as well as “Handle the empty field” if you would like. After that, click on the “Next” button to move to the next step.

How to use the HYPERLINK function in Salesforce

Step 9: The “Field Level Security” page is opened when you click the “Next” button. Select the profiles to which you want to allow field-level security editing access in order to customize the field-level security. This particular field will be hidden from all the profiles if you have not chosen the profile.

Check the checkbox next to “Visible” if you want this field to be shown on all profiles. To go to the next step, click the “Next” button.

How to use the HYPERLINK function in Salesforce Example

Step 10: After clicking the next button, the “Add Page Layout” page is opened. Select the page layout that will include the newly created custom formula field. Next, click the “Save” button from the menu.

Use the HYPERLINK function in Salesforce Classic

You can use the formula field after you have created it. Let’s look at an example to show how it works:

  • Open the Product item and create a new product and save it.
  • After saving, move to the Detail Section, here you will get the field “Product Manual”, which shows the hyperlink of the link.
Example of HYPERLINK function in Salesforce

With this, we have learned how to use the HYPERLINK function in Salesforce Classic.

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 implementation of how to use the HYPERLINK function in Salesforce Lightning and in Salesforce Classic.

You may like to read the following articles: