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
AiyazAiyaz 

Email Template (VisualForce) - How to show Contact information?

Hello All,
I am fairly new at the VF email templates so I have a question regarding a problem I am encountering.  First of all the Business Process is this: 
 
- send 'Contact A' an Email that contains all the details of another Contact including all of its Opportunities (from related list)
- 'Contact A' is related to these Opps because he/she is selected via a custom lookup field named 'Contact A' on the Opp. page
 
The problem i'm encountering is that I can only Associate Opportunities to Accounts but not the Contact which is why the following code only works if set  relatedToType="Account". It won't save if i set it to "contact".  
 
The second problem I am encountering is when sending an email , below the "To" field the "Related To" field does not allow "Contacts" to be pulled up which disallows the user to reference Contact fields.  Is there a way around this?  I would like to reference basic contact fields in the Email template including Phone, Email and Description field (long text).  Any help would be great with the code and with how to reference these contact fields or your own workaround.
 
Much thanks.
 
 
My Code:
<messaging:emailTemplate subject="Contact Data with Opps from Related list" recipientType="Contact" 

relatedToType="Account">

<messaging:htmlEmailBody >

 

 <html>

        <body>

         <STYLE type="text/css">

               TH {font-size: 11px; font-face: arial;background: #CCCCCC; border-width: 1;  text-align: center } 

               TD  {font-size: 11px; font-face: verdana } 

               TABLE {border: solid #CCCCCC; border-width: 1}

               TR {border: solid #CCCCCC; border-width: 1}

         </STYLE>

             <font face="arial" size="2">

                <p>Dear {!recipient.name},</p>

                <p>Below is a list of cases related to the account: {!relatedTo.name}.</p>

                <table border="0" >

                 <tr > 

                 

                     <th>Amount</th><th>Name</th><th>Close Date</th><th></th><th></th>

                 </tr>

                     <apex:repeat var="cx" value="{!relatedTo.Opportunities}">

                       <tr>

                          

                               <td>{!cx.Amount}</td>

                               <td>{!cx.Name}</td>

                               <td>{!cx.closeDate}</td>

                               

                       </tr>

                     </apex:repeat>

                 

                </table>

                <p />

             </font>

        </body>

 </html>

 

</messaging:htmlEmailBody>

</messaging:emailTemplate>