I have an HTML email template (NOT a VF template) that should be sent by a workflow rule when the record status is changed to Converted.

rather than a link to the record in SalesForce, I want a link on the email template to point to the record shown in my VF Page, so the link would be something like


I looked at Bob Buzzard's answer here and tried adding:

Click {HYPERLINK(Left($Api.Enterprise_Server_URL_190,(find('/services',$Api.Enterprise_Server_URL_190))) + Request_for_System_Change__c.Id, 'Request' )} 

I also put a special URL field in my custom object, which can be populated by the trigger on save. This new field is called link_to_request_)c and is populated in the Save event of my trigger as below:

String sUrlRewrite = System.URL.getSalesforceBaseUrl().getHost();

system.debug('sUrlRewrite  = ' + sUrlRewrite);
//  Example: c.cs7.visual.force.com
// https://cs87.salesforce.com/apex/SystemChangeRequest?id=a3K8E0000000CMyUAM&mode=view
sUrlRewrite = 'https://'
    + sUrlRewrite.substring(0,5) 
    + 'salesforce.com'
    + '/apex/SystemChangeRequest?mode=view&id='
    + sId;

r.link_to_request__c= sUrlRewrite;      

so in my email template I tried adding that as well, but when I click on the add link button in editing HTML template, it just shows me the add HTML link dialog:

enter image description here

and when the email is sent, it looks like this:

enter image description here

I am stuck with this, I could of course hard-code the domain name in each domain, but I'd rather try and have it done dynamically if possible.

UPDATE following answer by bennie

so I have a formula field in my custom object called UrlFormulaField using the formula LEFT($Api.Partner_Server_URL_360, FIND( '/services', $Api.Partner_Server_URL_360)) & '/apex/systemchangerequest?id=' & Id & '&mode=view' and this creates the correct URL as


so in my HTML template I want to add this as a Merge field link, but when I click add the Merge field, select it, click the add link button and paste in the merge field it doesn't add it as a link:

enter image description here

so what is the correct way to add the merge field as a link?

  • 1
  • @Ratan: Thanks but this is an assignment template used in a workflow with merge fields - how can I use this method to get my VF page with record Id as a link in my SF communication template? Feb 22, 2016 at 12:41
  • 1
    Have you created a Formula field with this {HYPERLINK(Left($Api.Enterprise_Server_URL_190,(find('/services',$Api.Enterprise_Server_URL_190))) + Request_for_System_Change__c.Id, 'Request' )} and use this formula field in email template
    – Ratan Paul
    Feb 22, 2016 at 12:47

1 Answer 1


First create a formula field Instance_URL__c on your object -

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

Now in your template use it as a merge field. I have taken Account object as an example.


In your instance something like

Click {!Request_for_System_Change__c.UrlFormulaField__c}{!Request_for_System_Change__c.Id} to go to change request

Click on link and insert the formula string like this

enter image description here

  • Thanks, and this looks good, but I am having trouble inserting it as a clickable link in my HTML Template. I am editing the HTML Template in SalesForce, and when I click on the add link button I get the script prompt as above in my question, but SF doesn't put a link in my email template when I click OK Feb 22, 2016 at 12:56
  • 1
    @OurManInBananas This above will create a simple text.. You need to wrapp this text inside HYPERLINK function.
    – Ratan Paul
    Feb 22, 2016 at 12:59
  • 1
    @OurManInBananas You are doing it wrong! Remove the default string http:// which appears on the 'Please enter URL' window. Just put {!Request_for_System_Change__c.UrlFormulaField__c}{!Request_for_System_Change__c.Id} as I suggested in my post and then put your text around it.
    – Jarvis
    Feb 22, 2016 at 14:24
  • 1
    @OurManInBananas As per your screenshot you are entering {!Request_for_System_Change__c.UrlFormulaField__c} whereas you have to put {!Request_for_System_Change__c.UrlFormulaField__c}{!Request_for_System_Change__c.I‌​d} for a proper URL to be constructed. Also make sure that you have created the formula field correctly.
    – Jarvis
    Feb 22, 2016 at 14:48
  • 1
    @Bennie, LOL, funny story, Internet Explorer strikes again, I waste 2 hours faffing around with this, almost shouting at my workstation, SalesForce, StackExchange... my colleague tried it on FireFox and guess what :) Feb 22, 2016 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.