function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

How to put URL dynamically in HTML email template

How to put URL dynamically in HTML email template, i want to populate url dynamically otherwise on every instance i have to chance the URL.

Some one please suggest me what we have to do here.
Mahesh DMahesh D
Hi Karna,

There is an idea on this topic, please vote for it.

There is a workaround for that... you can create a formula field of type text and insert the following:

LEFT($Api.Partner_Server_URL_260, FIND( '/services', $Api.Partner_Server_URL_260))

That will give you the ORG''s URL ... than let's Say that you have created the formula field above with the name of "ORG URL",  so you can type in on the template the following:

<a href={!YourObjectName.ORG_URL__c}/{!Opportunity.Id}>{!Opportunity.Name}</a>

Just make sure you replace the YourObjectName with the name of the object where you are running the workflow... so if you need to link it into another object via the lookup relationship you can get the ORG URL field that you created and merge with the ID of that object to put the link together. 


Also look into below posts:

Please do let me know if it helps you.

Mark RootMark Root
Here's what I ended up doing, using the standard "Link" field that comes with whatever record you're working with:
{!MID(Task.Link, 1, LEN(Task.Link)-15)}{whatever_you_want}

In my case, this produced:{whatever_you_want}

No need for a custom field, custom label, custom setting, or apex.
Sanjay Thakur 21Sanjay Thakur 21
Hi Mark,
This works for me
{!MID(User.Link, 1, LEN(User.Link)-15)}{!Target_User.Id}
Jithesh VasudevanJithesh Vasudevan
Brilliant. Thanks so much Mark Root and Sanjay Thakur. Your answer should be selected as the best answer. This totally works.
Bablu Kumar PanditBablu Kumar Pandit
Hi @Mark Root,

I need task Record Link so can you plz help me i am using {!MID(Task.Link, 1, LEN(Task.Link)-15)}{!Task.Id} in href tag but it is not working for me.plz let me know how do i used to get proper URL.
Mark RootMark Root
That should just be {!Task.Link} then, nothign else.
Ashutosh Mishra 18Ashutosh Mishra 18
Hi @Mark Root,

Could you please help me in getting Opportunity Link, using the Case Record. I tried different ways but not able to get Oppotunty Link using the Custom Look-up fields on Case Object

Thanks in Advance,
Ashutosh Mishra
Mark RootMark Root
Is the API name of your Opportunity field on Case something like "Opportunity__c"? If so, your email template link would look something like this: {!MID(Case.Link, 1, LEN(Case.Link)-15)}{!Case.OpportunityId__c} Mark.
Kirthana SyreddyKirthana Syreddy
Hi @Mark Root,

I used this {!MID(Task.Link, 1, LEN(Task.Link)-15)}{whatever_you_want} for a record link and it worked the way you explained. Thanks for that.  But how can we dynamically populate a lightning custom tab instead. 

In one of my email templates, I need to direct the user to a custom tab instead of a record on an object. And I don't want to hardcode the URL as we have different orgs. Please guide. Thanks!
Mark RootMark Root
Not totally sure what you're trying to accomplish here but, if your custom tabs are based off of custom objects, the first three characters of the record in the "Link" field on the template will take you to the tab (e.g., the Accounts tab is always 001 as all Account records start with 001). 

Since you have different orgs, though, you would want to check to see that they all have the same three character prefix.  If so, just use that.  If not, or your tab is based of off a Visualforce Page, you could create a Custom Label to store the value of the tab ID for each org and then create a formula field on whatever object you're using in the template to pull in the value of the Custom Label.  Hope that helps.

Talha SaqibTalha Saqib
Thanks @mahesh. The workaround worked.