Flow is the number one automation tool of Salesforce. There are endless things that you can perform using Salesforce Flow. In many cases, you might need to create a link to a record in flow. For instance, if it is a screen flow, you can display a link to the record. So that the users can navigate to the record by clicking the link. Another great use case is sending an email that contains a link to a record.
There are a few ways to create a record link in Salesforce Flow. The goal is to build a link in this format:
https://mydomain.lightning.force.com/recordId
As you can see, the first part will always be the same. You just have to put the record's id to the right side.
Since the left side of the link will be different in every environment (sandbox and production), it shouldn't be hardcoded. The important part is to make the link dynamic. So that after deploying the flow between environments, you won't need to edit the flow and fix the link. Therefore, it is not recommended to put a hardcoded link. So, how can you create a dynamic link?
Create a Link Using a Custom Label
The first option to create a link is using a custom label.
1- Create a custom label in setup and put your Salesforce environment's url as the value.
2- You can create a formula resource or a text template in order to create the record link. Use the Label global variable in order to bring the custom label that you created in the previous step. Then put a "/" and the record's id to the right side of the custom label.
After creating a resource for the record link, select the text that you want to display as hyperlink. Then, click on the link icon and use the resource that you created.
This option can be considered as half dynamic, because the first part of the url is still hardcoded in the custom label. When you deploy the custom label to another environment, don't forget to replace the value. Since it is coming from a custom label, you don't need to modify the flow. Once you change the value in the custom label, it will be reflected in your flows.
Create a Link Using API Global Variable
The second option is using the Api global variable. This global variable stores the Enterprise Server URL and Partner Server URL values.
There are many options for Enterprise Server URL and Partner Server URL in this global variable. However, as you can see from the screenshot below, they all start with the url of the environment. Therefore, you can use any of them in this use case.
1- Create a formula resource and add one of those global variables. Since you need the environment's url, you have to use some functions to remove the unnecessary part.
2- After creating the formula, select the text that you want to display as a hyperlink. Then, click on the link icon and use the resource that you created.
This option is completely dynamic and it is the recommended solution. Once you deploy the flow to another environment, you don't need to change anything.
Example
Here is a simple flow that creates an account record. After creating the account, the Id of the new account record is stored in the variable called {!Create_Account}. Then the flow displays a link for the new record, which lets the user navigate to the new record.
Here is the formula used in RecordLink_Formula resource:
LEFT({!$Api.Partner_Server_URL_550}, FIND( '/services', {!$Api.Partner_Server_URL_550})) & {!Create_Account}
After creating the record, it displays a hyperlink for the new account record.
When the users click on the link, their browser will open the destination link in a new tab. Although there is no parameter to control the target behavior of hyperlinks, there is a way to achieve this.
Read this post to learn how to control the target behavior of links in screen flows.
An Easier Option
There is an even easier option. However, please note that this method only works when displaying the link within the system (you cannot send this link by email). Basically, you will need to show /Id and since you are already within the system, it will automatically open the corresponding record. You don't even need to create a formula for this.
For instance, let's assume that you are creating an account record and you want to display the link of the new account. Just add a link to the display text component and write /{!Create_Account} as the Link URL. That's it!
Thank you! The complete dynamic solution really helped, but can you please explain the formula in detail?
Hi,
$Api global variable stores the API URLs.
For example, $Api.Enterprise_Server_URL_140 is the merge field value for version 14.0 of the Enterprise WSDL SOAP endpoint.
In this use case, we just need the URL (we can remove the part after .com). So using a formula, we just remove the part after .com and then we add the record Id. So it becomes the correct link for that record.
Hi Yumi -- This is super helpful. Quick question: On the dynamic formula you provided at the end of the article, did you mean to write {!Create_Account} in reference to the record ID or should it be {!recordId} as previously written further above?
Hi Neil,
In that example I am creating a new account and the Id is stored in {!Create_Account} variable. That's why I used it in the link.
Ok, that makes sense. Thanks!
Thank you!! Very helpful article.
How to send Fault Message from salesforce Flow to Email Template, as there is no $Flow.FaultMessage merge field available in email template?
I can think of 2 possible solutions:
1- Create a text template in flow and use the Send Email core action to send the email, not an email alert.
2- Save the value of the fault message to a custom field and use it in an email template/email alert.
This is great! One question I have is how did you embed your RecordLink_Formula into the "Click Here" text. In my use case I want to embed the record link into the standard field for record name.
Hi,
I selected the text (Click Here) on the screen and clicked the hyperlink icon, then put the RecordLink_Formula.
Thanks, Yumi. Great article.
When I copied across your formula the ' marks around /services came through as a different character, so I initially had a syntax error. Easy to fix for anyone else who may have the same problem.
You are right, thank you!
Thanks you Steven! I had the same issue. I really appreciate you taking the time to post that issue here, saved me some headaches.
THANK YOU for posting this. I was going crazy trying to figure out what was wrong. That fixed it!
I am glad that it helped!
Hi Yumi, Can we add Hyperlink to fields in datatable of screenflow? Thanks for your support.
Hi,
Data table can display formula fields with hyperlink. So, once I did a workaround. I updated a field on the record (from the same flow) and then displayed a formula field (that displays a link), which uses the value that I populated.
Hi Yumi,
Can you please give more details about how you did this? I need to add the hyperlink in a data table in screen flow.
More exactly, I am trying to display the related Quote Line Items on the Account level, but I cannot bring the lookup field ProductId in the screen flow and I need it to be displayed as a record link.
Thank you!
Hi,
The standard data table doesn't show lookup fields as clickable links. You can solve this issue by creating a text formula field on the Quote Line Item object. Use a formula like this:
HYPERLINK('/'&Product2Id, Product2.Name)
Then display this field instead of your lookup. This will navigate to the product record. If you want it to navigate to Quote Line Item record, build your formula field like this:
HYPERLINK('/'&Id, Product2.Name)
And of course, you can add target too. For example, if you want it to open the record in the same page, use '_self'
So in this case, your formula should be like this:
HYPERLINK('/'&Id, Product2.Name, '_self')
Had the same issue, did you figure out a resolution?
Hello Yumi
I need one help I want to. Open some screen flow or screen with some value after click link and after save or see screen return.same flow window
Can we open other screen window or screen flow same predefined value
It's lite urgent
Flows have URLs too, so it is possible to display the URL of the screen flow that you want to open. But in your use case, you might want to use a subflow instead.
Hi, thank you for this article; thought I would need a solution for a hyperlink in text template NOT IN A SCREEN ELEMENT (everywhere on the internet I found only the solution of a hyperlink in a screen element); I need it for a record-trigger flow and unfortunatelly in a text area is Click here
or Click here to open the record.
I would need to be displayed the 'Click here' hyperlink without the URL or the usual HTML tags in a text template.
Thank you; I would heartfully appreciate any help!
Hi, you can do the same logic to create a text template with "Click Here".
Create a formula resource for the record URL and then use it in your text template.
This is a great use case of including a "Click Here" in email bodies.
I'm getting an error trying to save the flow with that formula. It's an error like expecting text but getting boolean when I use the create record element rather than the record variable id. Any idea why?
Hi Kory,
Are you storing the new record's Id in a different text variable? If so, you have to use the variable that stores the Id of the new record.
Thank you,Yumi!
Very helpful article!
Thank you Anna!
Hi Yumi: I am new to Flows so this might sound stupid but, in the Jan 18 thread - is this how I can add Help Article links to the Plain Text email in my flow? The email didn't work in Rich Text so I modified it to Plain Text but then lost the URL links.
So researching how to do it, I found your articles and I think it's here but I am still trying to understand the best way to embed the URL links in the Plain Text email body.
Your assistance is greatly appreciated, I will wait for your reply.
Hi Laurie,
You can add the links to your plain text email body but you cannot use a hyperlink in this case.
Hi Yumi ,
I need to include link /url to salesforce report in notification body in scheduled flow.. I have tried above methods but it sending html tags. Can you please help on this.
Hi Divya,
Notification body doesn't support rich text (including hyperlinks). That's why it is displaying as a plain text with html tags.
Do you want to make the user navigate to the report? I think you can get the Id of the report (using Get Records element) and then use the Id as the Target Id of the send custom notification action.
Hi,
I am using this formula LEFT({!$Api.Partner_Server_URL_550}, FIND( '/services', {!$Api.Partner_Server_URL_550})) & {!create_child}
but when i am clicking the link it is re-directing me to the start of the screen flow instead of redirecting to the new child record page.
Can you please help me on this
Is {!create_child} storing the Id of the record or is it a boolean?
Can you right click the hyperlink, then copy the link and send me? Let's see if it is correct.
the latest issue I am facing is , using the formula LEFT({!$Api.Partner_Server_URL_550}, FIND( '/services', {!$Api.Partner_Server_URL_550})) & {!create_child}
is redirecting the user to classic page instead of lightning , can you please help on this
Hey
Using the formula I am using this formula LEFT({!$Api.Partner_Server_URL_550}, FIND( '/services', {!$Api.Partner_Server_URL_550})) & {!create_child} it's redirecting to classic page , how can we make sure it's redirect to lightning page?
Please help
Hi Yumi ,
this is issue is solved thanks for the reply , the latest issue I am facing is , using the formula LEFT({!$Api.Partner_Server_URL_550}, FIND( '/services', {!$Api.Partner_Server_URL_550})) & {!create_child}
is redirecting the user to classic page instead of lightning , can you please help on this
Can you send me how the final link looks like?
This is great information. I am still having a couple of issues.
I get the correct URL for a lightning page, but the link appears this way:
Click here
The Click here isn't highlighted and the URL appears next to it.
Then when I do the same thing in production, my URL formula doesn't work at all.
Here is my URL formula:
Left({!$Api.Enterprise_Server_URL_100}, FIND( '/services', {!$Api.Enterprise_Server_URL_100})) & {!$Record.Milestone_Survey__r.Id}
Here is the html from the plain text version:
Click here
Any help will be greatly appreciated.
Hi Tommie,
Are you using this inside a display text element? If so, write Click Here and then highlight these words. Then put {!MilestoneSurveyURL} as the Link URL.
Hi can we add multiple record links in a text template in a table form may be to include multiple record names with their record links?
Hi,
I just published a new post about this. Let me know if it helps.
https://salesforcetime.com/2023/11/02/how-to-send-email-with-a-record-table-in-flow/
Excellent article, really useful stuff in there.
Out of interest, is there a reason not to use a relative URL and simply prepend "/" to the record ID? Something like:
"/"&{!recordId}
This ought to link to the relevant "page" on the current domain, right?
Thank you! Yes, you can do that as well.
Hello sir , I have a question
What I want is my link let it as this : click here but when the user click on this link it redirects him to the record
Hi, yes it is exactly what this post is about. You can create the link as mentioned in the post and display it using a display text component.
Hello. I have followed the instruction on this and went with the first option. The link works but just takes me to home page of our salesforce instance. This is my fomula:
{!$Label.SalesforceURL}&"/"&{!recordId}
Any ideas why?
I have a flow that is triggered when an opportunity is changed to closed won. It runs asynchronously because a message is being sent to slack.
Hi, what is the flow type? Can it be that your recordId variable is null?