+ Start a Discussion

Using outputLinks in visualforce email templates

How can I use a relative salesforce URl link in a visualforce email template?  For example, instead of the following, which works, but uses a hard coded host url:


<a href="https://na6.salesforce.com/{!relatedTo.Id}">https://na6.salesforce.com/{!relatedTo.Id}</a>

I want something lilke this, but the outputLink tags cause an error when the email is sent from the email api using this template...


<apex:outputLink value="/{!relatedTo.Id}">{!relatedTo.Id}</apex:outputLink>


Since there is not a way to associate a custom controller with a visualforce email template, how can I specify the URL in a non-hardcoded way?

Ken KoellnerKen Koellner

I faced the same problem without ouputLink without using any controller.


I tried--

<apex:outputlink value="{!relatedTo.Id}">{!relatedTo.Name}</apex:outputlink></p>

 But the email contained a bad link-- http://006v0000001urepiaq/


If you want to use a custom controller with VF message templates, it can be done but indirectly.  You have to create a VF page that uses a custom component and then included the custom component in your VF template.