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
MrTheTylerMrTheTyler 

Creating Salesforce Links in VisualForce Email Templates

Wow, I just can't seem to figure this simple thing out.  In a visualforce template I want to create a link to an object record. 

 

I've seen examples like this

 

 

({!LEFT($Api.Partner_Server_URL_140, FIND(".com/",$Api.Partner_Server_URL_140)+3)

 

but shouldn't I be able to use a simple relative URL to get this to work?

 

 

 

 

A new record was created!  <a href="/{!RelatedTo.ID}">Click here</a>  to see it.

 

 

However, when the email gets sent out the link becomes "http://5008000000dmoskaax/" and not "http://na8.salesforce.com/5008000000dmoskaax"

 

 

 

Any idears?

 

 

 

Tyler

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Relative URLs only make sense in the context of a web server - i.e. they are relative to the root of the server. A relative URL in an email doesn't have a root so it is assumed to be an absolute URL.

 

The formula based on the partner server url is the only way I've found to achieve this.

All Answers

bob_buzzardbob_buzzard

Relative URLs only make sense in the context of a web server - i.e. they are relative to the root of the server. A relative URL in an email doesn't have a root so it is assumed to be an absolute URL.

 

The formula based on the partner server url is the only way I've found to achieve this.

This was selected as the best answer
JoyDJoyD

Does it work in the preview before sending the email?  I copied and pasted your example and that works for me - but when it sends, it looses the 'context' - so my guess is that you'll have to hardcode the beginning of the URL (or use some nifty way of generating it that I can't think of offhand)...

MrTheTylerMrTheTyler

It does work in preview but as Bob Buzzard said the email has no server context.  The server partner url code I pasted above had some comments about links breaking in special cases such as european users vs american users.  I was hoping there was a clean way to do this as it is pretty crucial and used over and over again.  Alas.

Ken KoellnerKen Koellner

Can someone explain w


bob_buzzard wrote:

Relative URLs only make sense in the context of a web server - i.e. they are relative to the root of the server. A relative URL in an email doesn't have a root so it is assumed to be an absolute URL.

 

The formula based on the partner server url is the only way I've found to achieve this.


Can someone explain what this "formula" is?

Ken KoellnerKen Koellner

I hacked around with that formulate to get a complete syntax that actualy works in the email template--

 

<apex:outputlink value="{!LEFT($Api.Partner_Server_URL_140,FIND('.com',$Api.Partner_Server_URL_140)+4)+relatedTo.Id}">{!relatedTo.Name}</apex:outputlink>

 

You need to use single quotes in the expressions within the value attribute so as not to confuse the double-quotes that delimit it.

 

I used 4 unlike the +3 so I got the "/".

EllenHEllenH

Ken - I know this is an old post, but I was playing around with similar functionality and could not get it straight...  In searching I came across this post.   The line you posted worked great and I learned a little something.  Thank you for posting.

Ken KoellnerKen Koellner

Glad I could help.  It's always neat learning other peoples' tricks.  And SF is a bit of a maverick environment so it helps.

 

-Ken

 

Alexis KasperaviciusAlexis Kasperavicius
Ken,

Nice trick! Perfect solution.

Thank you!

IT Main OneIT Main One
Worked for me.

Thank you
Kunaal Patodia 6Kunaal Patodia 6
Is there a way to get the value of $Network.NetworkUrlForUserEmails in a VF Email Template ?
DevAccountDevAccount
Hi @bob_buzzard 

We have custom domain/url setup for our production community, So will this $Api.Partner_Server_URL_140 based formula return custom domain URL (non force.com domain)?

Thanks!