0

I have created my first visualforce email template using apex:repeat. I am not getting any errors but I am not receiving any data. Fields outside of repeat are being populated with data. Any help will be much appreciated.

<messaging:emailTemplate subject="Project: [{!relatedTo.Project__r.Name}] has missing or innacurate information" 
    recipientType="Contact" 
    replyTo="test@g.com"
    relatedToType="Incident__c">

<messaging:htmlEmailBody >        
    <html>
        <body>

        <p>Dear {!relatedTo.Project__r.Contact__r.Name},</p>

        <p>
           The items below need attention before continuing with project: {!relatedTo.Project__r.Name}. 
           Incident numnber: {!relatedTo.Name}.
        </p>

     <table border="0" >
       <tr> 
         <th>Stage</th>
         <th>Type</th>
         <th>Created Date</th>
       </tr>

    <apex:repeat var="pt" value="{!relatedTo.Measure_Rules__r}">   <!-- Notice the "s" here per the child relationship in the lookup field settings -->
         <tr>
           <td> <apex:outputField > value="{!pt.Rule_Stage_Calc__c}" </apex:outputfield></td>
           <td> <apex:outputField > value="{!pt.Type__c}" </apex:outputfield></td>
           <td> <apex:outputField > value="{0, date, MM-dd-yyy}" <apex:Param value="{!pt.CreatedDate}"/> </apex:outputfield></td>
         </tr>   
    </apex:repeat>                 
    </table>

       <p>
          Please call our customer service department at 1-800-xxx-xxxx.
       </p>     

       <p>
          Thanks,<br/>
          TBD Team
       </p>                

     </body>
 </html>

</messaging:htmlEmailBody>             
</messaging:emailTemplate>
  • Hi David, thanks for the link. Does this mean that we cannot use {!relatedTo.Measure_Rules__r} and repeat, and that the only way to accomplish this is via a class and a component? Sounds like a lot of work just for a list on an email. Let me know. Thanks! – Snights Aug 26 at 15:21
  • 1
    Yes, you have to build a VF component with controller to retrieve and list the child records, then place the component in your VF email template. – David Cheng Aug 26 at 15:46

Browse other questions tagged or ask your own question.