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
alcamadialcamadi 

Create an email template with visualforce

Hello
I´m new with visualforce and I need to create an email template to show data of the opportunity, show the related quote and show the list of a custom object (call CE) that is related to the quote. The next is an example of what a need:

 

- Quote has a relation master detail with opportunity
- CE (My_custom_object) has a relation master detail with quote

 

Dear {!recipient.Name}

 

{!Opportunity.Name}
{!Opportunity.closeDate}
{!Quote.name}
{!Quote.date}

 

(here I need to show a table with the list of items of my custom object)
Code- Name - Date

 

I hope you understand me. I appreciate your help.

Best Answer chosen by Admin (Salesforce Developers) 
SabrentSabrent

seems like the child name is not referenced properly.
You can check the Relationship name in salesforce schema. Go to Parenet object, drill down to child relationships and find the relationship name.


you should have a name that ends with __r


Hop this helps.

All Answers

SabrentSabrent

This should give you an idea - 

 

<messaging:emailTemplate recipientType="Contact" relatedToType="Account" subject="Case report for Account: {!relatedTo.name}" replyTo="support@test123.com" >
<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>Action</th><th>Case Number</th><th>Subject</th><th>Creator Email</th><th>Status</th>
            </tr>     
            
       <apex:repeat var="cx" value="{!relatedTo.Cases}">
         <tr>
             <td><a href="https://naX.salesforce.com/{!cx.id}">View</a> | 
             <a href="https://naX.salesforce.com/{!cx.id}/e">Edit</a></td>
             <td>{!cx.CaseNumber}</td>
             <td>{!cx.Subject}</td>
             <td>{!cx.Contact.email}</td>
             <td>{!cx.Status}</td>
         </tr>
      </apex:repeat>  
  </table>
            <p/>
            </font>
        </body>
</html>        
</messaging:htmlEmailBody>
</messaging:emailTemplate>

 

alcamadialcamadi

Thank you for your reply.

 

I have this:

 

<messaging:emailTemplate recipientType="Contact" relatedToType="Quote" subject="Expiration date reminder " >
    <messaging:htmlEmailBody >
        <html>
        <body>
            <p>Hello {!recipient.FirstName}</p>
            <p>The Quote number {!relatedTo.QuoteNumber} will expire on {!relatedTo.ExpirationDate}. </p>
            <apex:outputPanel >
                <apex:outputText >
                    <table border="1">
                        <tr>
                            <td>Course Status</td>
                            <td>Course Code</td>
                            <td>Course Name</td>
                            <td>Duration(Days)</td>
                            <td>Begin Date</td>
                            <td>End Date</td>
                            <td>Location</td>
                            <td>Language</td>
                        </tr>   
                <apex:repeat var="qce" value="{!relatedTo.Course_Requirement__c}">
                     <tr>
                        <td>{!qce.Course_Status__c}</td>
                        <td>{!qce.Course_Code__c}</td>
                        <td>{!qce.Course_Name__c}</td>
                        <td>{!qce.Course_Duration_days__c}</td>
                        <td><apex:outputField value="{!qce.Course_Begin_Date__c}"/></td>
                        <td><apex:outputField value="{!qce.Course_Ending_Date__c}"/></td>
                        <td>{!qce.Course_City_location__c}</td>
                        <td>{!qce.Language_Delivery__c}</td>
                     </tr>            
                </apex:repeat>
                    </table>
                </apex:outputText>
            </apex:outputPanel>
            </body>
        </html>
    </messaging:htmlEmailBody>
</messaging:emailTemplate>

 

 

 It shows me this Error: Invalid field Course_Requirement__c for SObject Quote and i really don´t know what should i do to make it work. I want to show the information of the course requirements related to the quote.

SabrentSabrent

seems like the child name is not referenced properly.
You can check the Relationship name in salesforce schema. Go to Parenet object, drill down to child relationships and find the relationship name.


you should have a name that ends with __r


Hop this helps.

This was selected as the best answer
alcamadialcamadi

Thank you rov, you were right, i was missing the __r.

SabrentSabrent

can you please mark this as resolved so that others can reuse the solution where applicable.