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

Related List in VF Email Template

I am new to Visualforce Email Templates so any help is greatly appreciated!  Thanks!


I have an email template that I want to fire off of a custom object (Policy__c) but I want to pull in the Related List that appears on the Policy object - the Related List is called Claims.  Below is the code I have but the error I keep getting is:


Error: Invalid field Claims__r for SObject Policy__c


<messaging:emailTemplate subject="90 Day Policy Expiration: {!}" recipientType="Contact" relatedToType="Policy__c">
<messaging:plainTextEmailBody >
The following policy has an Expiration Date that is within 90 days from today.

Policy: {!relatedTo.Name}
Insured: {!relatedTo.Insured__c}
Effective Date: {!relatedTo.Effective_Date__c}
Expiration Date: {!relatedTo.Expiration_Date__c}
Underwriter: {!relatedTo.Underwriter__c}
Underwriting Branch Office: {!relatedTo.Underwriting_Branch_Office__c}

<apex:repeat value="{!relatedTo.Claims__r}">


Best Answer chosen by Admin (Salesforce Developers) 

I was able to get help from Support on this one and got to a really great solution so I thought I would share the code that worked and produced a great table showing all the records that appeared in the related list.




<messaging:emailTemplate subject="90 Day Policy Expiration Notification: {!} - {!}" recipientType="Contact" relatedToType="Policy__c">
<messaging:htmlEmailBody >
<p> Dear {!},</p>
<p>Below is information pertaining to a policy that has an Expiration Date that is within 90 days from today.  If you require additional information, please respond to this email and you will be directed appropriately.  </p>
<p>Thank you</p>
<p>Policy: {!relatedTo.Name}
<p>Insured:  {!}
<p>Effective Date:  <apex:outputText value="{0,date,MM/dd/yyyy}"><apex:param value="{!relatedTo.Effective_Date__c}"/></apex:outputText>
<p>Expiration Date: <apex:outputText value="{0,date,MM/dd/yyyy}"><apex:param value="{!relatedTo.Expiration_Date__c}"/></apex:outputText>
<p>Underwriter:  {!}
<p>Underwriting Branch Office:  {!relatedTo.Underwriting_Branch_Office__c}
<table border="1">
<th>Claim Number</th>
<th>Claimant Name</th>
<th>Policy Number</th>
<th>Claim Status</th>
<th>Date Reported</th>
<apex:repeat var="rc" value="{!relatedTo.Claims1__r}">
<td>{!rc.Name} </td>
<td><apex:outputText value="{0,date,MM/dd/yyyy}"><apex:param value="{!rc.Date_Reported__c}"/></apex:outputText></td>