Last active
January 20, 2017 12:04
-
-
Save arjun00231/9421c8a9b477cd6525dea774701ab9af to your computer and use it in GitHub Desktop.
Create a pdf of vf page and attach to the record.
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 PageReference generatePdf() { | |
//PageReference pdf = new PageReference('/apex/yourPageName'); | |
//Page.yourPageName; | |
PageReference targetPage = Page.yourPageName; | |
targetPage.getParameters().put('id',objOpp.Id); | |
//pdf.setRedirect(true); | |
system.debug('<<<<<<<pdf : '+targetPage); | |
Attachment attach = new Attachment(); | |
Blob targetBody; | |
// try { | |
targetBody = targetPage.getContentAsPDF(); | |
// } catch ( VisualforceException exp ) { | |
// targetBody = Blob.valueof('There was an error.'); | |
// } | |
attach.Body = targetBody; | |
attach.ContentType = 'application/pdf'; | |
attach.Name = 'Final quote- '+objOpp.Name +' '+String.valueof(Datetime.now())+'.pdf'; | |
attach.IsPrivate = false; | |
attach.ParentId = objOpp.Id; | |
insert attach; | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment