<messaging:emailTemplate recipientType="Contact" relatedToType="Account" subject="Case report for Account: {!relatedTo.name}" replyTo="support@acme.com"> <messaging:htmlEmailBody> <html> <body> <p>Dear {!recipient.name},</p> <p>Attached is a list of cases related to {!relatedTo.name}.</p> <center> <apex:outputLink value="http://www.salesforce.com"> For more detailed information login to Salesforce.com </apex:outputLink> </center> </body> </html> </messaging:htmlEmailBody> <messaging:attachment> <apex:repeat var="cx" value="{!relatedTo.Cases}"> Case Number: {!cx.CaseNumber} Origin: {!cx.Origin} Creator Email: {!cx.Contact.email} Case Number: {!cx.Status} </apex:repeat> </messaging:attachment> </messaging:emailTemplate>
这个标记在电子邮件中作为附加的数据文件呈现,没有任何格式。您可以使用以下选项之一以更易读的格式显示数据:更改文件名
<messaging:attachment>标记具有一个名为filename的属性,用于定义附加文件的名称。定义一个容易识别的名字是一个好习惯,但这不是必需的。如果不确定,Salesforce会为您生成一个名称。 没有扩展名的文件名默认为文本文件。您可以将附件呈现为CSV格式: <messaging:attachment filename="cases.csv"> <apex:repeat var="cx" value="{!relatedTo.Cases}"> {!cx.CaseNumber} {!cx.Origin} {!cx.Contact.email} {!cx.Status} </apex:repeat> </messaging:attachment> 您也可以将数据呈现为HTML文件: <messaging:attachment filename="cases.html"> <html> <body> <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> 尽管您只能为每个<messaging:attachment>组件定义一个文件名,但可以将多个文件附加到电子邮件中。更改呈现属性
与其他Visualforce页面类似,在<messaging:attachment>组件上将renderAs属性设置为PDF将使该附件呈现为PDF。例如: <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> Visualforce PDF呈现服务的限制包括以下内容。- PDF是唯一支持的呈现服务。
- PDF呈现服务呈现PDF版本1.4。
- 将Visualforce页面呈现为PDF文件适用于为打印设计和优化的页面。
- 作为PDF文件呈现的Visualforce页面显示在浏览器中,或根据浏览器的设置进行下载。具体行为取决于浏览器,版本和用户设置,并且不受Visualforce的控制。
- PDF呈现服务在您的页面上呈现标记和数据,但是它可能不会呈现包含在添加到页面的富文本区域内容中的格式。
- 没有断点的长行文本(如空格或破折号)不能由PDF呈现服务打包。这通常发生在非常长的URL,注册表项等等。当这些行比页面宽时,它们会增加页面内容的宽度,超出PDF页面的边缘。这会导致内容从页面“流”,切断它。
- 不要使用不易打印格式的标准组件,或输入或按钮等表单元素,或任何需要JavaScript格式的组件。
- PDF渲染不支持JavaScript呈现的内容。
- Salesforce应用程序中的页面不支持PDF呈现。
- 页面上使用的字体必须在Visualforce PDF呈现服务上可用。 Web字体不受支持。
- 如果PDF文件无法显示所有页面的文本,特别是多字节字符(如日文或重音国际字符),请调整CSS以使用支持它们的字体。 例如: <apex:page showHeader="false" applyBodyTag="false" renderAs="pdf"> <head> <style> body { font-family: 'Arial Unicode MS'; } </style> </head> <body> これはサンプルページです。<br/> This is a sample page: API version 28.0 </body> </apex:page> “Arial Unicode MS”是包含多字节字符的扩展字符集所支持的唯一字体。
- 如果使用内联CSS样式,请将API版本设置为28.0或更高版本。同样设置<apex:page applyBodyTag =“false”>,并在页面中添加静态的,有效的<head>和<body>标签,就像前面的例子。
- 创建PDF文件时的最大响应大小必须小于15 MB,然后才能呈现为PDF文件。此限制是所有Visualforce请求的标准限制。
- 生成的PDF文件的最大文件大小为60 MB。
- 生成的PDF中包含的所有图像的最大总大小为30 MB。
- PDF呈现不支持以数据:URI方案格式编码的图像。
- 以PDF形式呈现时,以下组件不支持双字节字体。 – <apex:pageBlock> – <apex:sectionHeader> 不推荐将这些组件用于以PDF形式呈现的页面。
- 如果<apex:dataTable>或<apex:pageBlockTable>没有呈现<apex:column>组件,则将该页呈现为PDF失败。 要解决此问题,请将表组件的呈现属性设置为false,如果未呈现其任何子<apex:column>组件。