- Text
- HTML (using letterhead)
- Custom (without using letterhead)
- Visualforce
Since Visualforce e-mail templates allow you to create PDF attachments, your next logical move will be to port your HTML templates to VF and create a PDF attachment (invoice, receipt, whatever).
That is great for your external users's confirmation but what if you want to send a very similar email (including attachments) to your internal user and include a link? That is when things get interesting.
On a template related to a lead, you would think it would be as simple as {!RelatedTo.Link}. You would be wrong and would get this error message:

Basically the problem is that this isn't an actual field and the visual force engine for email templates hasn't been configured to build a link in place of this logic. You can easily confirm this by opening up force.com explorer and trying to query for the field. When you do, you will get an error like this:
So how do you get your link into your email template? Well you could create a formula field and hard code in your Salesforce instance but that isn't portable. The correct way is to use some visualforce creativity to make a relative link:
<apex:outputlink value="{!LEFT($Api.Partner_Server_URL_140,FIND('.com',$Api.Partner_Server_URL_140)+4)+relatedTo.Id}">Link</apex:outputlink>
This will work brilliantly for the HTML section of your email template but in your plain text template, you want to use just the text and not the link. So you modify the visualforce to look like this:
<apex:outputtext value="{!LEFT($Api.Partner_Server_URL_140,FIND('.com',$Api.Partner_Server_URL_140)+4)+relatedTo.Id}"/>
Now you have the text of your link in the email but unfortunately you can't insert a blank line before this link (at least as far as I know) - it will appear on the same line (at least in the preview) no matter how many blank lines you put in front of it.
I have got a question from your article.
ReplyDeleteI am trying to understand, can't we use {!Lead.link} in visual force templates? (or) is this only for standard object? I just confused little bit.
When do we have to use:
apex:outputlink......
(I mean is it only when we have attachments?)
Babu,
ReplyDeleteThe .Link field isn't an actual field in the database. My understanding is that the HTML email template parser will insert a link to a record for an object (standard or custom) when it sees this 'field' in its markup. As you can see from my article, this option isn't directly available in the parser for visual force email templates.
This is most likely due to the agile development method that sales force uses.
Until this is fixed, use the .link in HTML templates and the above outputlink for visual force email templates.
Just note that if your visual force email template gets read by a text email client then there is a good change the formatting will be missing a blank line before the link.
Thanks,
Anthony
Thanks a lot Coleman
ReplyDeleteExelent response
ReplyDeleteThanks!