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?

Regards, Satish

1 Answer 1


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: {!relatedTo.name}"

replyTo="[email protected]">

    <p>Dear {!recipient.name},</p>
    <p>Attached is a list of cases related to {!relatedTo.name}.</p>
    <apex:outputLink value="http://www.salesforce.com">
        For more detailed information login to Salesforce.com

<messaging:attachment renderAs="PDF" filename="yourCases.pdf">
    <p>You can display your {!relatedTo.name} 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>

  • Thanks Mohith for sharing the sample code. Actually, the messaging:attachment cannot be used in a repeat statement. Please check this link - salesforce.stackexchange.com/questions/12899/…
    – user7101
    Aug 25, 2014 at 2:35
  • If you use in apex component then you have problems.Here in this case you should be fine Aug 25, 2014 at 5:43
  • Hi Mohith, Still it is a problem. The above codes, send an email with attachment (PDF) and inside the attachment it does have the information of the 'Notes & Attachment'. But, what I am looking for is, the email is sent with 'Notes & Attachment' attachments which will be in xls format. -Satish
    – user7101
    Aug 25, 2014 at 8:35
  • for example, in an Opportunity record, under Notes & Attachment, we upload "Special-Deals.xls". Now, we want to send an email to our users on the Opportunity record and in the very same email the uploaded "Special-Deals.xls" is attached as an attachment. I appreciate your help & advise. -Satish
    – user7101
    Aug 25, 2014 at 8:43
  • You will need to go with second approach of sending just the link while you cant send actual attacment Aug 25, 2014 at 9:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .