I have a Visualforce email template that is being used as part of a WFR Email Alert. I have multiple recipients in the email alert. How would I get my VF template to email each of these recipients?

VF Template:

<messaging:emailTemplate recipientType="Contact"
  subject="Notification - {!relatedTo.Name} - {!TODAY()}"
  <messaging:htmlEmailBody >
        <STYLE type="text/css">
          TH {font-size: 11px; font-face: arial;background: #CCCCCC;
               border-width: 1;  text-align: center } 
          TD  {font-size: 11px; font-face: verdana } 
          TABLE {border: solid #CCCCCC; border-width: 1}
          TR {border: solid #CCCCCC; border-width: 1}
        <font face="arial" size="2">
          <p>Hi {!recipient.Name},</p>
          <p>We would like to inform you of the following issue(s) found on {!relatedTo.Name}.&nbsp;We would appreciate your immediate attention to this matter.<br/></p>
          <table border="0" columns="2">
            <apex:variable value="{!1}" var="ViolationNum"/>
            <apex:repeat var="cx" value="{!relatedTo.Cases}">
            <apex:outputPanel rendered="{!IF(cx.Status = 'Escalated Internal - Past Due' && cx.Escalate_to_Client__c = TRUE,TRUE,FALSE)}">
                    <td colspan="2"><b><u>Violation #<apex:outputText value="{!FLOOR(ViolationNum)}"/></u></b></td>
                    <apex:variable var="ViolationNum" value="{!ViolationNum + 1}"/>
                    <td width="25%">Case Number</td>
                    <td width="75%">&nbsp;&nbsp;&nbsp;{!cx.CaseNumber}</td>
                    <td width="25%">Site Name(s)</td>
                    <td width="75%">&nbsp;&nbsp;&nbsp;{!cx.Sample_URLs__c}</td>
                    <td width="25%">Violation Type</td>
                    <td width="75%">&nbsp;&nbsp;&nbsp;{!cx.Type_of_Violation__c}</td>
                    <td width="25%">Description of Violation</td>
                    <td width="75%">&nbsp;&nbsp;&nbsp;{!cx.Compliance_Violation_Description__c}</td>

            Please respond to this email by 
                <b><apex:outputText value="{0, date, MMMM d','  yyyy}">
                    <apex:param value="{!CASE( MOD( TODAY() - DATE(1900, 1, 7), 7),0, TODAY() + 2,1, TODAY() + 2,2, TODAY() + 2,3, TODAY() + 2,4, TODAY() + 4,5, TODAY() + 4,6, TODAY() + 3,null)}"/>

            Thank you for your prompt attention to this matter!<br/><p/>

1 Answer 1


I met this problem before, it is also know bug, see salesforce known issues

Short: relatedTo does not work if Visualforce email template is invoked through workflow.

Workarounds - you are allowed to use relatedTo only. If your relatedTo object has a contact lookup than you can refer contact fields through that relationship like: relatedTo.Contact__r.Name

  • 1
    Thanks, I was afraid of that. A "bug" for 5 years...guess it's not getting fixed anytime soon.
    – J. Neilan
    Jun 30, 2016 at 14:15
  • Unless I've missed some important update, this bug is still occurring ... another 5 years later. What's strange in my case is this only occurs when used for a community New Member - Welcome Email. Other emails work just fine using {!$User.FirstName} Jul 7, 2021 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.