+ Start a Discussion
Madhu007Madhu007 

Adding the attachment in Pdf

Hi all, I have a vf template. it will render as pdf and able send the mail. I have a attachemnt with case object. i want to add this attachment to vf template. Can please help me.

Thanks. 
YuchenYuchen
You can try to add something like this to your vf template:

 
<messaging:attachment renderAs="PDF" filename="cases.pdf">
	<html>
		<body>
		<p>You can display your {!relatedTo.name} cases as a PDF:</p>
			<table border="0" >
			<tr>
				<th>Case Number</th><th>Origin</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}">{!cx.CaseNumber}
				</a></td>
				<td>{!cx.Origin}</td>
				<td>{!cx.Contact.email}</td>
				<td>{!cx.Status}</td>
			</tr>
			</apex:repeat> 
		</table>
		</body>
	</html>
</messaging:attachment>




Reference Link: https://www.salesforce.com/docs/developer/pages/Content/pages_email_templates_attachments.htm
 
Madhu007Madhu007
Hi Yuchen,

whatever you have given that is like making case information as attachment and rendered as pdf. That we have already implemented. what my quetion is i have a case record with attachment(related list). i have a vf template with same like your code for rendering case information as a pdf. With this vf template i want to add the attachmnet which is tagged with the case.

Thanks,
 
YuchenYuchen
Maybe you can add the following code between the <messaging:htmlEmailBody> tag:
<apex:repeat value="{!relatedTo.Attachments}" var="a">
<p><a href="{!URLFOR($Action.Attachment.Download, a)}">{!a.Name}</a> ({!a.BodyLength} B)</p>
</apex:repeat>

You can also refer to the below links:
https://developer.salesforce.com/forums/ForumsMain?id=906F000000096IjIAI
https://developer.salesforce.com/forums/ForumsMain?id=906F000000097JHIAY