3

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"
  relatedToType="Account"
  subject="Notification - {!relatedTo.Name} - {!TODAY()}"
  replyTo="test@test.com">
  <messaging:htmlEmailBody >
    <html>
      <body>
        <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}
        </STYLE>
        <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)}">
                <tr>
                    <td colspan="2"><b><u>Violation #<apex:outputText value="{!FLOOR(ViolationNum)}"/></u></b></td>
                    <apex:variable var="ViolationNum" value="{!ViolationNum + 1}"/>
                </tr>
                <tr>
                    <td width="25%">Case Number</td>
                    <td width="75%">&nbsp;&nbsp;&nbsp;{!cx.CaseNumber}</td>
                </tr>
                <tr>
                    <td width="25%">Site Name(s)</td>
                    <td width="75%">&nbsp;&nbsp;&nbsp;{!cx.Sample_URLs__c}</td>
                </tr>
                <tr>
                    <td width="25%">Violation Type</td>
                    <td width="75%">&nbsp;&nbsp;&nbsp;{!cx.Type_of_Violation__c}</td>
                </tr>
                <tr>
                    <td width="25%">Description of Violation</td>
                    <td width="75%">&nbsp;&nbsp;&nbsp;{!cx.Compliance_Violation_Description__c}</td>
                </tr>
                <br/><br/>
            </apex:outputPanel>
            </apex:repeat>
            </Table>

            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)}"/>
                </apex:outputText></b>.<p/>

            Thank you for your prompt attention to this matter!<br/><p/>
        </font>
      </body>
    </html>
  </messaging:htmlEmailBody> 
</messaging:emailTemplate>
2

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

  • Thanks, I was afraid of that. A "bug" for 5 years...guess it's not getting fixed anytime soon. – J. Neilan Jun 30 '16 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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