You need to sign in to do that
Don't have an account?
Girbson Bijou 7
Send Visualforce PDF as attachment
Hi all, I have a VF page rendered as PDF which display data from on object. I need to send this pdf as attachement to an email every week day.
Please explain me how to do it step by step.
The class is:
public class InventoryReport {
public List<AggregateResult> allproduct{get;set;}
public InventoryReport() {
allproduct = [
SELECT Product_Hiden_Name__c, UM__c ,SUM(On_Hand__c)onHand, SUM(Pending__c)pending, SUM(Available__c)avail
FROM Articles_Containers__c
WHERE IsOpened__c = 1
GROUP BY Product_Hiden_Name__c , UM__c
HAVING SUM(On_Hand__c) >0
ORDER BY Product_Hiden_Name__c, UM__c limit 1000];
}
}
The page is
<apex:page controller="InventoryReport" renderAs="pdf" showHeader="false" sidebar="false" standardStylesheets="false" applyBodyTag="false" >
<head>
<style type="text/css" media="print">
tr {
//font-family: Consolas, monaco, monospace;
// font-weight:6px;
font-size:12px;}
@page {
@bottom-left {
content: element(footer);
size:letter;
}
}
// .tablebody{
// font-size=18px;
// }
/* .sectionHeader {
width: 100%;
//background-color: #eee;
font-size: 20pt;
padding: 0px;
margin: 15px 0px;
font-weight: bold;
}*/
.head{
width:65%;
display: table;
}
.col {
display:table-cell;
line-height:1.1em;
vertical-align: middle;
}
.logo{
width: 30%;
}
.name{
width: 70%;
}
.name h2, .name h6{
margin: 0;
padding: 0;
margin-left: 10px;
line-height: 1.1em;
}
.tableHeader {
border-width: 0px 0px 0px 0px;
border-color: #000;
border-style: solid;
}
table {
width: 100%;
}
.centered {
text-align: center;
}
h3{
text-align: center;
}
.right {
text-align: right;
}
.firstBlock
{
width: 90%;
margin-left: 20px;
}
.beneInfo{
border-width: 1px 1px 1px 1px;
border-style: solid;
margin: 20px;
}
.SubfirstBlock{
display:table-cell;
width:800px;
line-height: 1.5em;
}
.tableBeneinfo{
display:table-cell;
width:800px;
line-height: 1.2em;
}
.tableBeneinfo div{
border-top: 1px solid black;
display: inline;
margin-right:5px;
width: 100px;
text-align:center;
}
.footer {
display: block;
padding: 5px;
position: running(footer);
margin-bottom: 20px
}
.signature
{margin-top:30px
}
.subfooter {
display: inline-block;
}
.status{
width: 30%;
background-color: #eee;
font-size: 12pt;
padding: 5px;
margin: 20px 0px;
font-weight: bold;
}
div.right {
float: right;
}
.pagenumber:before {
content: counter(page);
}
.pagecount:before {
content: counter(pages);
}
</style>
</head>
<div class="head">
<div class="col logo">
<apex:image url="{!$Resource.LogoFFP}" width="140" height="60"/>
</div>
<div class ="col name">
<h2>
FOOD FOR THE POOR
</h2>
<h6>
14, Mapou Rte. Nationale #1
Cap Haitien, Haiti. Tels:(+509)2208-9960/3409-5328
</h6>
</div>
</div>
<br/>
<h3> INVENTORY STOCK STATUS REPORT UPDATED ON:<apex:outputtext value="{0, date, Long}">
<apex:param value="{!NOW()}"></apex:param>
</apex:outputtext> <br/></h3>
<br/>
<div class="table">
<div class="tableHeader">
<th>ITEM</th>
<th>UNIT OF MEASURE </th>
<th>ON HAND </th>
<th>PENDING </th>
<th>AVAILABLE </th>
</div>
<apex:repeat value="{!allproduct}" var="a">
<!-- <div class="tablebody"> -->
<tr>
<td>{!a['Product_Hiden_Name__c'] }</td>
<td>{!a['UM__c']}</td>
<td>{!a['OnHand']}</td>
<td>{!a['Pending']}</td>
<td>{!a['avail']}</td>
</tr>
</apex:repeat>
</div>
<div class="footer">
<div>
Printed by : {!$User.FirstName} {!$User.LastName} <apex:outputtext value="{0, date, long}">
<apex:param value="{!NOW()}"></apex:param>
</apex:outputtext> <br/>
As often as you did it for one of my least brothers, you did it for me. Matthiew 25:40 <br/>
</div>
</div>
</apex:page>
Please explain me how to do it step by step.
The class is:
public class InventoryReport {
public List<AggregateResult> allproduct{get;set;}
public InventoryReport() {
allproduct = [
SELECT Product_Hiden_Name__c, UM__c ,SUM(On_Hand__c)onHand, SUM(Pending__c)pending, SUM(Available__c)avail
FROM Articles_Containers__c
WHERE IsOpened__c = 1
GROUP BY Product_Hiden_Name__c , UM__c
HAVING SUM(On_Hand__c) >0
ORDER BY Product_Hiden_Name__c, UM__c limit 1000];
}
}
The page is
<apex:page controller="InventoryReport" renderAs="pdf" showHeader="false" sidebar="false" standardStylesheets="false" applyBodyTag="false" >
<head>
<style type="text/css" media="print">
tr {
//font-family: Consolas, monaco, monospace;
// font-weight:6px;
font-size:12px;}
@page {
@bottom-left {
content: element(footer);
size:letter;
}
}
// .tablebody{
// font-size=18px;
// }
/* .sectionHeader {
width: 100%;
//background-color: #eee;
font-size: 20pt;
padding: 0px;
margin: 15px 0px;
font-weight: bold;
}*/
.head{
width:65%;
display: table;
}
.col {
display:table-cell;
line-height:1.1em;
vertical-align: middle;
}
.logo{
width: 30%;
}
.name{
width: 70%;
}
.name h2, .name h6{
margin: 0;
padding: 0;
margin-left: 10px;
line-height: 1.1em;
}
.tableHeader {
border-width: 0px 0px 0px 0px;
border-color: #000;
border-style: solid;
}
table {
width: 100%;
}
.centered {
text-align: center;
}
h3{
text-align: center;
}
.right {
text-align: right;
}
.firstBlock
{
width: 90%;
margin-left: 20px;
}
.beneInfo{
border-width: 1px 1px 1px 1px;
border-style: solid;
margin: 20px;
}
.SubfirstBlock{
display:table-cell;
width:800px;
line-height: 1.5em;
}
.tableBeneinfo{
display:table-cell;
width:800px;
line-height: 1.2em;
}
.tableBeneinfo div{
border-top: 1px solid black;
display: inline;
margin-right:5px;
width: 100px;
text-align:center;
}
.footer {
display: block;
padding: 5px;
position: running(footer);
margin-bottom: 20px
}
.signature
{margin-top:30px
}
.subfooter {
display: inline-block;
}
.status{
width: 30%;
background-color: #eee;
font-size: 12pt;
padding: 5px;
margin: 20px 0px;
font-weight: bold;
}
div.right {
float: right;
}
.pagenumber:before {
content: counter(page);
}
.pagecount:before {
content: counter(pages);
}
</style>
</head>
<div class="head">
<div class="col logo">
<apex:image url="{!$Resource.LogoFFP}" width="140" height="60"/>
</div>
<div class ="col name">
<h2>
FOOD FOR THE POOR
</h2>
<h6>
14, Mapou Rte. Nationale #1
Cap Haitien, Haiti. Tels:(+509)2208-9960/3409-5328
</h6>
</div>
</div>
<br/>
<h3> INVENTORY STOCK STATUS REPORT UPDATED ON:<apex:outputtext value="{0, date, Long}">
<apex:param value="{!NOW()}"></apex:param>
</apex:outputtext> <br/></h3>
<br/>
<div class="table">
<div class="tableHeader">
<th>ITEM</th>
<th>UNIT OF MEASURE </th>
<th>ON HAND </th>
<th>PENDING </th>
<th>AVAILABLE </th>
</div>
<apex:repeat value="{!allproduct}" var="a">
<!-- <div class="tablebody"> -->
<tr>
<td>{!a['Product_Hiden_Name__c'] }</td>
<td>{!a['UM__c']}</td>
<td>{!a['OnHand']}</td>
<td>{!a['Pending']}</td>
<td>{!a['avail']}</td>
</tr>
</apex:repeat>
</div>
<div class="footer">
<div>
Printed by : {!$User.FirstName} {!$User.LastName} <apex:outputtext value="{0, date, long}">
<apex:param value="{!NOW()}"></apex:param>
</apex:outputtext> <br/>
As often as you did it for one of my least brothers, you did it for me. Matthiew 25:40 <br/>
</div>
</div>
</apex:page>
Please follow this url:-
http://blog.jeffdouglas.com/2010/07/16/create-and-email-a-pdf-with-salesforce-com/
if you have anhy further issue please tell me.
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
https://gist.github.com/msrivastav13/6291713