+ Start a Discussion
Sumant KuchipudiSumant Kuchipudi 

How can we get Salesforce Base URL in email template?

Hi,
I'm bulding an Approval process, for that I'm preparing an email (Text) template to include VisualForce page link so that approvars opens that page and submit. I can get the Salesforce Base URL from apex but I have no clue how to get it form email template.
See the following template that I have gotten from APEX.
<a href='https://'+ System.URL.getSalesforceBaseUrl().getHost() +  
             '/apex/GUGocardPhotoApprovalPage?ContactId='+contactID'>Click here </a>

 
Aman BishtAman Bisht
Hi Sumant ,

Just remove https: and also change .getHost() with .ToExternalForm()
<a href='+System.URL.getSalesforceBaseUrl().ToExternalForm() +  
             '/apex/GUGocardPhotoApprovalPage?ContactId='+contactID'>Click here </a>



Thanks
sethi0007771.395862520819969E12sethi0007771.395862520819969E12
Hey Aman,
It's not working for img src in email template, Can u suggest please?
<img src="'+System.URL.getSalesforceBaseUrl().ToExternalForm() + 
             '/servlet/servlet.ImageServer?id=0151200000323j&oid=00DA0000232&lastMod=142661854233"
 alt="#1 in customer satisfaction over all other cable and satellite providers(4)" width="147" height="142" style="display: block;" border="0">

Thanks,
Rahul
Adam CadamAdam Cadam
System.URL.getSalesforceBaseUrl().ToExternalForm() in an email template is just treated as text - it is not executed, so doesn't expand out to an actual URL.
There's a community ticket asking for this - go there and add your vote, but don't hold your breath waiting for an answer.
The ticket is already 7 years old!
https://success.salesforce.com/ideaView?id=08730000000b3PjAAI
Adam CadamAdam Cadam
System.URL.getSalesforceBaseUrl().ToExternalForm() in an email template is just treated as text - it is not executed, so doesn't expand out to an actual URL.
There's a community ticket asking for this - go there and add your vote, but don't hold your breath waiting for an answer.
The ticket is already 7 years old!
https://success.salesforce.com/ideaView?id=08730000000b3PjAAI
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:
https://marine-dev-ed.my.salesforce.com/{whatever_you_want}

No need for a custom field, custom label, custom setting, or apex.
Danny van DelftDanny van Delft
In a Classic email template I ended by doing something like

{!Case.Link}/../{whatever_you_want}

The assumption here is that moving one level up (the /../) from the Case URL, or whatever record Link, will get you to the Base URL. Works like a charm, in my case at least.