You need to sign in to do that
Don't have an account?

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
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
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.
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)...
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.
Can someone explain w
Can someone explain what this "formula" is?
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 "/".
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.
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
Nice trick! Perfect solution.
Thank you!
Thank you
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!