You need to sign in to do that
Don't have an account?
valeria jasarevic
How to fix error for Email Template with PDF attachment | Error occurred trying to load the template for preview: PDF generation failed. Check the page markup is valid.. Please try editing your markup to correct the problem.
First time doing my own Visual Force Email Template. I thought I had it all and then this message shows up:
Error occurred trying to load the template for preview: PDF generation failed. Check the page markup is valid.. Please try editing your markup to correct the problem.
Here is what my template looks like
<messaging:emailTemplate subject="Packaging Request from {!$User.FirstName} " recipientType="Contact" relatedToType="Opportunity">
<messaging:plainTextEmailBody >
{!recipient.name},
We have a packaging request for {!$Organization.Name}. Please find attached the PDF with all the relevant information
Regards,
{!$User.FirstName} {!$User.LastName}
<br/>
</messaging:plainTextEmailBody>
<messaging:attachment renderAs="pdf" filename="{!relatedTo.name}">
<table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
<tr>
<td>
<img src='{!URLFOR($Resource.LOGO)}' title="logo" />
</td>
<td align="right"><font face="Arial" >
<b>Packaging Word Order for {!relatedTo.Account.Name}</b></font><br/>
</td>
</tr>
<hr/>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
<tr> <td><font face="Arial" >
{!$Organization.Name}<br/>
{!$Organization.Street}<br/>
{!$Organization.PostalCode} {!$Organization.City}<br/>
{!$Organization.Country}<br/>
</font></td>
<td width="60%"> </td>
<td ><font face="Arial">Ship Date: {!relatedTo.CloseDate} <br/>
<br/>
Requested by: <br/>
{!relatedTo.Owner.LastName} {!relatedTo.Owner.FirstName}</font>
</td>
</tr>
</table>
<br/>
<hr/>
<p><b><font face="Arial" color="#000080">Customer Information</font></b></p>
<table border="0" width="100%" id="table2">
<tr>
<td colspan="3">
<font face="Arial">Account name: {!relatedTo.Account.Name} <br/><br/></font>
</td>
</tr>
<tr>
<td>
<font face="Arial">Bill To:<br/>
{!relatedTo.Account.BillingStreet}<br/>
{!relatedTo.Account.BillingPostalCode} {!relatedTo.Account.BillingCity}
</font>
</td>
<td width="50%"></td>
<td >
<font face="Arial">Ship To:<br/>
{!relatedTo.Account.ShippingStreet}<br/>
{!relatedTo.Account.ShippingPostalCode} {!relatedTo.Account.ShippingCity}
</font>
</td>
</tr>
</table>
<br/>
<hr/>
<p><b><font color="#000080" face="Arial">Products</font></b></p>
<table border="0" width="100%" id="table4">
<tr>
<td bgcolor="#C0C0C0"><font face="Arial">Product</font></td>
<td bgcolor="#C0C0C0"><font face="Arial">Image</font></td>
<td bgcolor="#C0C0C0"><font face="Arial">Quantity</font></td>
</tr>
<tr>
<apex:repeat value="{!relatedTo.OpportunityLineItems}" var="line">
<tr>
<td>{!line.PricebookEntry.Name}</td>
<td ALIGN="center"><img src='{!line.PricebookEntry.Product2.URL_Picture__c}'/></td>
<td>{!line.Quantity}</td>
</tr>
</apex:repeat>
</tr>
<tr>
</tr>
</table>
<br/>
<hr/>
<p><b><font color="#000080" face="Arial">Custom Conditions</font></b></p>
<table border="0" width="100%" id="table3">
<tr>
<td><font face="Arial">
<b>Packaging Notes {!relatedTo.Packaging_Notes__c}</b></font><br/>
</td>
</tr>
</table>
<p align="center"><font face="Arial"><i>Copyright {!$Organization.Name}.</i></font></p>
</messaging:attachment>
</messaging:emailTemplate>
Does anyone know how to correct this??
Error occurred trying to load the template for preview: PDF generation failed. Check the page markup is valid.. Please try editing your markup to correct the problem.
Here is what my template looks like
<messaging:emailTemplate subject="Packaging Request from {!$User.FirstName} " recipientType="Contact" relatedToType="Opportunity">
<messaging:plainTextEmailBody >
{!recipient.name},
We have a packaging request for {!$Organization.Name}. Please find attached the PDF with all the relevant information
Regards,
{!$User.FirstName} {!$User.LastName}
<br/>
</messaging:plainTextEmailBody>
<messaging:attachment renderAs="pdf" filename="{!relatedTo.name}">
<table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
<tr>
<td>
<img src='{!URLFOR($Resource.LOGO)}' title="logo" />
</td>
<td align="right"><font face="Arial" >
<b>Packaging Word Order for {!relatedTo.Account.Name}</b></font><br/>
</td>
</tr>
<hr/>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
<tr> <td><font face="Arial" >
{!$Organization.Name}<br/>
{!$Organization.Street}<br/>
{!$Organization.PostalCode} {!$Organization.City}<br/>
{!$Organization.Country}<br/>
</font></td>
<td width="60%"> </td>
<td ><font face="Arial">Ship Date: {!relatedTo.CloseDate} <br/>
<br/>
Requested by: <br/>
{!relatedTo.Owner.LastName} {!relatedTo.Owner.FirstName}</font>
</td>
</tr>
</table>
<br/>
<hr/>
<p><b><font face="Arial" color="#000080">Customer Information</font></b></p>
<table border="0" width="100%" id="table2">
<tr>
<td colspan="3">
<font face="Arial">Account name: {!relatedTo.Account.Name} <br/><br/></font>
</td>
</tr>
<tr>
<td>
<font face="Arial">Bill To:<br/>
{!relatedTo.Account.BillingStreet}<br/>
{!relatedTo.Account.BillingPostalCode} {!relatedTo.Account.BillingCity}
</font>
</td>
<td width="50%"></td>
<td >
<font face="Arial">Ship To:<br/>
{!relatedTo.Account.ShippingStreet}<br/>
{!relatedTo.Account.ShippingPostalCode} {!relatedTo.Account.ShippingCity}
</font>
</td>
</tr>
</table>
<br/>
<hr/>
<p><b><font color="#000080" face="Arial">Products</font></b></p>
<table border="0" width="100%" id="table4">
<tr>
<td bgcolor="#C0C0C0"><font face="Arial">Product</font></td>
<td bgcolor="#C0C0C0"><font face="Arial">Image</font></td>
<td bgcolor="#C0C0C0"><font face="Arial">Quantity</font></td>
</tr>
<tr>
<apex:repeat value="{!relatedTo.OpportunityLineItems}" var="line">
<tr>
<td>{!line.PricebookEntry.Name}</td>
<td ALIGN="center"><img src='{!line.PricebookEntry.Product2.URL_Picture__c}'/></td>
<td>{!line.Quantity}</td>
</tr>
</apex:repeat>
</tr>
<tr>
</tr>
</table>
<br/>
<hr/>
<p><b><font color="#000080" face="Arial">Custom Conditions</font></b></p>
<table border="0" width="100%" id="table3">
<tr>
<td><font face="Arial">
<b>Packaging Notes {!relatedTo.Packaging_Notes__c}</b></font><br/>
</td>
</tr>
</table>
<p align="center"><font face="Arial"><i>Copyright {!$Organization.Name}.</i></font></p>
</messaging:attachment>
</messaging:emailTemplate>
Does anyone know how to correct this??
First, remove the 'renderAs="pdf"' attr to check the inner error,
(I suggest to add <html> and <body> tag to the <messaging:attachment> tag.)
If there's no error that you saved successfully, add the 'renderAs="pdf"' attr back.
After save you may get that error massage again, but ignore it, just try to send a test email, maybe you can get the pdf attachment successfully.
I just recieved the correct email with correct PDF attachemnt while the error message still on.
So maybe it's an 'error' error message.
That's how I fixed this. I hope it could help.