Hi Friends,
In this post i m writing how to add the attachment to Note
& Attachment of Salesforce.com from VF-Page which is rendered as “pdf”
from detail page Custom button.
Here the Custom button code its of onclick java script behaviour:-
window.showModalDialog('/apex/PDF_Page?id={!Lead.Id}','',"
dialogWidth:800px;dialogHeight:500px; center:yes | no | 1 | 0 | on | off");
location.reload(true);
dialogWidth:800px;dialogHeight:500px; center:yes | no | 1 | 0 | on | off");
location.reload(true);
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page renderAs="pdf" standardController="Lead" extensions="PDF_Page_Controller" action="{!savePDF}"> | |
This is the Pdf page of Lead "{!lead.Name}". | |
</apex:page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PDF_Page_Controller{ | |
Lead lead {get;set;} | |
public PDF_Page_Controller.PDF_Page_Controller(ApexPages.StandardController controller){ | |
lead = (Lead)controller.getRecord(); | |
} | |
public void savePDF(){ | |
PageReference PR = Page.PDF_Page_demo; | |
Attachment att = new Attachment(); | |
att.Name = lead.Name + '.pdf'; | |
att.ParentId = lead.Id; | |
att.body = PR.getContentAsPdf(); | |
insert att; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page renderAs="pdf" standardController="Lead" extensions="PDF_Page_Controller"> | |
This is the Pdf page of Lead "{!lead.Name}". | |
</apex:page> |
Here i used two VF-Pages to avoid recursive calling of VF Page because I am saving Attachment of page to Notes and
Attachment of same object.
Note:-
Remember not to call the method from "PDF_Page_demo".
Happy Coding...:)
here the sceern shots:-