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
Robin GrayRobin Gray 

Hello, Is there a way to have fields in a related list populate in a email template that is sent by a workflow?

Dimitri MitsiosDimitri Mitsios
Hello Robin,
you can use a visualforce email template , see below a working example
parent object:Quote
relates list with a custom Object ContainerLine Items
I hope will help you!
Dimtiri

<messaging:emailTemplate subject="Arrival Notice Consirnation  Quote:{!relatedTo.QuoteNumber} / {!relatedTo.Booking_Ref__c}" recipientType="User" relatedToType="Quote">
    <messaging:htmlEmailBody >
    <img src="https://c.eu0.content.force.com/servlet/servlet.ImageServer?id=01520000003iuwa&oid=00D20000000CpOP&lastMod=1463391182000"/>
     <p>&nbsp;</p>
        <body style="font-family: 'Tahoma'">
        <table border="1" cellpadding="1" cellspacing="1" style="width:800px;">
    <tbody> 
        <tr>
            <td style="text-align: center;"><span style="color:#0000FF;"><span style="font-size:36px;">&Beta;&Epsilon;&Beta;&Alpha;&Iota;&Omega;&Sigma;&Eta; &Alpha;&Nu;&Alpha;&Mu;&Epsilon;&Nu;&Omega;&Mu;&Epsilon;&Nu;&Eta;&Sigma; &Alpha;&Phi;&Iota;&Xi;&Epsilon;&Omega;&Sigma; &Epsilon;&Mu;&Pi;&Omicron;&Rho;&Epsilon;&Upsilon;&Mu;&Alpha;&Tau;&Omega;&Nu;</span></span></td>
        </tr>
    </tbody>
</table>
            <p>&nbsp;</p>
         <p><span style="font-size:20px;"><span style="font-family:tahoma,geneva,sans-serif;">{!relatedTo.Account_Pros__c}</span></span></p>

<p><span style="font-size:20px;"><span style="font-family:tahoma,geneva,sans-serif;">{!relatedTo.Arrival_Notice_Blue_Desr__c}</span></span></p>
<p><span style="font-size:20px;"><span style="font-family:tahoma,geneva,sans-serif;">{!relatedTo.Collect_Freight_Description__c}</span></span></p>


<p><span style="font-size:20px;"><span style="font-family:tahoma,geneva,sans-serif;">&Tau;&alpha; &sigma;&tau;&omicron;&iota;&chi;&epsilon;&iota;&alpha; &tau;&omicron;&upsilon; &phi;&omicron;&rho;&tau;&iota;&omicron;&upsilon; &epsilon;ί&nu;&alpha;&iota;:</span></span></p>

            <br />
            <table cellpadding="5" style="border-collapse: collapse" width="100%">
                <tr>
                    <td style="background-color: #0099CC; color: #FFFFFF">
                        <b>Container No</b>
                    </td>
                    <td style="background-color: #0099CC; color: #FFFFFF">
                        <b>Container Type</b>
                    </td>
                    <td style="background-color: #0099CC; color: #FFFFFF">
                        <b>House BL</b>
                    </td>
                    <td style="background-color: #0099CC; color: #FFFFFF">
                        <b>Content</b>
                    </td>
                     <td style="background-color: #0099CC; color: #FFFFFF">
                        <b>Quantity</b>
                    </td>    
                    <td style="background-color: #0099CC; color: #FFFFFF">
                        <b>Weight(Kgs)</b>
                    </td>
                    <td style="background-color: #0099CC; color: #FFFFFF">
                        <b>Volume(cbm)</b>
                    </td>
                    <td style="background-color: #0099CC; color: #FFFFFF">
                        <b>Shipper Name</b>
                    </td>
                </tr>
                <apex:repeat value="{!relatedTo.Container_Line_Items__r}" var="lineItem">
                        <tr>
                            
                            <td>
                                {!lineItem.Container_No__c}
                            </td>
                            <td>
                                {!lineItem.Container_Type__c}
                            </td>
                            <td>
                                {!lineItem.HBL_HBL__c}
                            </td>
                            <td>
                                {!lineItem.Content__c}
                            </td> 
                            <td>
                                {!lineItem.No_of_Packages__c}
                            </td> 
                            <td>
                                {!lineItem.Weight__c}
                            </td>     
                             <td>
                                {!lineItem.Volume__c}
                            </td>              
                             <td>
                                {!lineItem.Shipper_Name__c}
                            </td>                                                                    
                        </tr>
                </apex:repeat>
            </table>
        </body>
        <table border="0" cellpadding="1" cellspacing="1" style="width:500px;">
        <p>&nbsp;</p>
  <p><span style="font-family:tahoma,geneva,sans-serif;"><span style="font-size:20px;">&Mu;&epsilon; &phi;&iota;&lambda;&iota;&kappa;&omicron;ύ&sigmaf; &chi;&alpha;&iota;&rho;&epsilon;&tau;&iota;&sigma;&mu;&omicron;ύ&sigmaf;</span></span></p>

<p><span style="font-family:tahoma,geneva,sans-serif;"><span style="font-size:20px;">{!$User.FirstName} {!$User.LastName}</span></span></p>

<p><span style="font-family:tahoma,geneva,sans-serif;"><span style="font-size:20px;">{!$User.Title}</span></span></p>

<p><span style="font-family:tahoma,geneva,sans-serif;"><span style="font-size:20px;">{!$User.Street} </span></span></p>

<p><span style="font-family:tahoma,geneva,sans-serif;"><span style="font-size:20px;">{!$User.PostalCode} {!$User.City}</span></span></p>

<p><span style="font-family:tahoma,geneva,sans-serif;"><span style="font-size:20px;">{!$User.Country} </span></span></p>

<p><span style="font-family:tahoma,geneva,sans-serif;"><span style="font-size:20px;">Tel: {!$User.Phone}&nbsp; </span></span></p>

<p><span style="font-size:20px;">Mobile: {!$User.MobilePhone}&nbsp;</span></p>
</table>
    </messaging:htmlEmailBody>
</messaging:emailTemplate>
 
Robin GrayRobin Gray
Hi Dimtiri,

This will be my first attempt at Visualforce, I'll use your template as an example.  The custom object I'm using this for is called "Engagements" and the related list custom object is called "FMI Services".  I'm trying to get FMI Services fields to show up on an email that I'm sending to my finance department to obtain a code for invoicing.  Currently only the fields for the Engagement custom object is populating on a email template and I'm wanting to add the fields from the FMI Services to the email template.

Any advice on what to change on your template?  I'm planning on doing the Trailhead module for Visualforce Basics.

Thanks,
Robin
Dimitri MitsiosDimitri Mitsios
Robin, Ideally I would use an appexchange to generate the template for you Try Docomotion is really good and no code, we use it for all the official email correspondence Definitely change the quote to Engagements and Container Line Item to FMI Services Cheers dimitris