Add Attachment from Notes and Attachment related list in a VF Email template

I have a requirement and I appreciate your help on this.

We have a custom object, where users create records and upload spreadsheets in “Notes & Attachment” related list.

Our requirement is, we wanted to create a VF email template that adds the attachment (xls) of the record. This VF email template will be used in our standard Approval Process.

How do i go about?



Messaging:attachment documentation should help you to form the attachment by yourself rather than asking user to fill in excel if data is derived from salesforce objects and fields

The code mentioned is as below

<messaging:emailTemplate recipientType="Contact"


subject="Case report for Account: {!}"


    <p>Dear {!},</p>
    <p>Attached is a list of cases related to {!}.</p>
    <apex:outputLink value="">
        For more detailed information login to

<messaging:attachment renderAs="PDF" filename="yourCases.pdf">
    <p>You can display your {!} cases as a PDF</p>
    <table border="0" >
        <th>Case Number</th><th>Origin</th>
        <th>Creator Email</th><th>Status</th>
    <apex:repeat var="cx" value="{!relatedTo.Cases}">
        <td><a href = 

Lets say you want exact attachment that user has modified ,then consider sending as link

here is some example for same

<messaging:emailTemplate subject="hai" recipientType="Contact" relatedToType="Case">
 <messaging:htmlEmailBody >
<p>Attachment to download link</p>

<apex:repeat value="{!relatedTo.Attachments}" var="a">
<p><a href="{!URLFOR($Action.Attachment.Download, a)}">{!a.Name}</a> ({!a.BodyLength} B)</p>

Source : Link , Question Author : user7101 , Answer Author : Mohith Shrivastava

Leave a Comment