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
NevDevNevDev 

How to add a table to an email template

Hi guys,

Is it possible to add a table to an email template?
Ashish GargAshish Garg
Hi,
You need to create a Visualforce Template type email template for this. In the same, then you can create Apex:Datatable or simple html table.
Remember: style classes does not work in email template, for this use inline style classes thoughout the html.

Thanks,
Ashish Garg
Amit Chaudhary 8Amit Chaudhary 8
Please check below post for Visualforce email template
1) https://developer.salesforce.com/page/VisualForceEmailTemplates_sample

I hope below will help you
<messaging:emailTemplate recipientType="Contact"
  relatedToType="Account"
  subject="Case report for Account: {!relatedTo.name}"
  replyTo="support@acme.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://na1.salesforce.com/{!cx.id}">View</a> |  
                <a href="https://na1.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:plainTextEmailBody >
    Dear {!recipient.name},
    
    Below is a list of cases related to Account: {!relatedTo.name}
    
    [ Case Number ] - [ Subject ] - [ Email ] - [ Status ]
    
    <apex:repeat var="cx" value="{!relatedTo.Cases}">
      [ {!cx.CaseNumber} ] - [ {!cx.Subject} ] - [ {!cx.Contact.email} ] - [ {!cx.Status} ]
    </apex:repeat>
    
    For more information login to http://www.salesforce.com
  </messaging:plainTextEmailBody>    
</messaging:emailTemplate>

 
Stancioiu Stefan 1Stancioiu Stefan 1
Hi guys, Anybody help me to write this batch? I'm new on salesforce. Thanks !

1.  Create a batch class that summarizes all Opportunity Amounts for each Account;
2.  An email should be sent to the primary contact of all Accounts, containing a table with the Closed Won/Open/Closed Lost summarized Opportunity Amounts;
3.  Schedulable class that calls the batch class should be created;
4.  The class should be scheduled from the Developer console. Please provide script to schedule the job daily at 10:00 AM, once a week (Friday at 1:00 PM), once a month(Last Friday of the Month at 6:00 PM).