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" 

<messaging:htmlEmailBody >        

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

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

     <table border="0" >
         <th>Created Date</th>

    <apex:repeat var="pt" value="{!relatedTo.Measure_Rules__r}">   <!-- Notice the "s" here per the child relationship in the lookup field settings -->
           <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>

          Please call our customer service department at 1-800-xxx-xxxx.

          TBD Team


  • 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 '19 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 '19 at 15:46

Browse other questions tagged or ask your own question.