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
lemuellemuel 

Visualforce email template with Apex code tests okay,doesn't work from Send Email button

I've got a Visualforce email template with some Apex code that works fine when I test it from the "Send Test and Verify Merge Fields" feature of the email template editor, but fails to merge any data when I use the "Send an Email" button (from anywhere) and then "Select Template" to select it.

 

The code for the template is:-

 

<messaging:emailTemplate subject="Closing of Old xxxx Support Cases" recipientType="Contact" relatedToType="Contact">
<messaging:htmlEmailBody >
<html><body>
<h3>Closing of Old xxxx Support Cases</h3>
<p>Dear {!recipient.name},</p>
<p>the Cases listed below have had no activity recorded for more than three months. If we do not hear from you we will close these Cases after 5 working days from the date of this email.
If you would like further information about any of these Cases they can be viewed in the xxxx Support Portal from the links below.</p>
<font size="-1"><p >(To use the links below, first logon on to the
<a href="https://ap1.salesforce.com/secur/login_portal.jsp?orgId=00Dx0000000xxxx&portalId=060x0000000xxxx">xxxx Support Portal</a>)</p>
</font>
<table border="0" >
<tr><th> CaseNumber </th><th>Subject</th><th>Last Updated</th></tr>
<apex:repeat var="cx" value="{!relatedTo.Cases}">
<apex:outputPanel rendered="{!cx.Status == 'New'}" >
<tr><td>{!cx.CaseNumber}</td>
<td><apex:outputText value="{!cx.Portal_Friendly_Link_NoLogon__c}" escape="false" /></td>
<td><apex:outputText value=" {0,date,' 'dd' 'MMM' 'yyyy}' ' ">
<apex:param value="{!cx.LastModifiedDate}" />
</apex:outputText></td>
</tr>

</apex:outputPanel>
</apex:repeat>
</table>
<p>You have recieved this message because you are recorded as the Contact for these Cases. If you believe that
another person in your business is dealing with any of these Cases please forward this message to that person.</p>
<p>Thank you,<br/>
xxxx Support</p>
</body></html>
</messaging:htmlEmailBody>

<messaging:plainTextEmailBody >
Sorry, you need an html compatible mail client for this email.

xxxx Support
</messaging:plainTextEmailBody>

</messaging:emailTemplate>

 

I expected it to work when I selected the template from the "Send an Email" button on a Contact record.

I guess the first question would be, should it work when I try to use it this way? Or have I missed a limitation of Visualforce email templates? I also notice that when I use the "Send an Email" button, the list of Objects in the "Related To" drop down doesn't include Contacts.

 

If this is a limitation, how can I use the template?

 

(Also, I should mention that the test in <apex:outputPanel rendered="{!cx.Status == 'New'}" > is just for testing and will be changed to the proper one when I get it working and move it from the Developer environment to production.)