Visualforce Email Template supports to access a related list
or related object records by using relatedTo.reationshipObjectName.
In the below example, showed Contact and Opportunity records
related the Account object.
Here,
Account --> Parent Object
Contact and Opportunity --> Child Objects
In email template,
Contact records accessed by relatedTo.Contacts
Opportunity records accessed by relatedTo.Opportunities
Sample VF Template:
- <messaging:emailTemplate subject="Your Detailed Contact and Opportunities" recipientType="User" relatedToType="Account">
- <messaging:htmlEmailBody >
- <p> Dear {!relatedTo.Name}, </p>
- The following customers are waiting for your approval,
- <ul>
- <apex:repeat var="cn" value="{!relatedTo.contacts}">
- <li>
- {!cn.Name}
- </li>
- </apex:repeat>
- </ul>
- The following opportunities are ready to close,
- <ul>
- <apex:repeat var="cn" value="{!relatedTo.opportunities}">
- <li>
- {!cn.Name}
- </li>
- </apex:repeat>
- </ul>
- <p> Thanks, </p>
- <p> Sales Team </p>
- </messaging:htmlEmailBody>
- </messaging:emailTemplate>
Thank you for this!
ReplyDeleteIs it possible get grand child records to display in vf template?
ReplyDeletethanks.