Reply
Regular Contributor
MrTheTyler
Posts: 129
0
Accepted Solution

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

 

 

 

Moderator
bob_buzzard
Posts: 6,418
0

Re: Creating Salesforce Links in VisualForce Email Templates

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.

--
Certified Salesforce Technical Architect, Developer, Advanced Developer, Administrator, Advanced Administrator, Consultant, Sales Cloud Consultant,Service Cloud Consultant
Force.com MVP | The Bob Buzzard Blog | Linked In | Twitter

I don't respond to private messages/emails asking for help.


Take the Bob Buzzard Sobject Fields quiz.

Regular Contributor
JoyD
Posts: 53
0

Re: Creating Salesforce Links in VisualForce Email Templates

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)...

Regular Contributor
MrTheTyler
Posts: 129
0

Re: Creating Salesforce Links in VisualForce Email Templates

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.

Trusted Contributor
Ken Koellner
Posts: 202
0

Re: Creating Salesforce Links in VisualForce Email Templates

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?

Trusted Contributor
Ken Koellner
Posts: 202

Re: Creating Salesforce Links in VisualForce Email Templates

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 "/".

Contributor
EllenH
Posts: 8
0

Re: Creating Salesforce Links in VisualForce Email Templates

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.

Trusted Contributor
Ken Koellner
Posts: 202
0

Re: Creating Salesforce Links in VisualForce Email Templates

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