Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. public PageReference generatePdf() {
  2. //PageReference pdf = new PageReference('/apex/yourPageName');
  3. //Page.yourPageName;
  4. PageReference targetPage = Page.yourPageName;
  5. targetPage.getParameters().put('id',objOpp.Id);
  6. //pdf.setRedirect(true);
  7. system.debug('<<<<<<<pdf : '+targetPage);
  8.  
  9. Attachment attach = new Attachment();
  10. Blob targetBody;
  11. // try {
  12. targetBody = targetPage.getContentAsPDF();
  13. // } catch ( VisualforceException exp ) {
  14. // targetBody = Blob.valueof('There was an error.');
  15. // }
  16. attach.Body = targetBody;
  17. attach.ContentType = 'application/pdf';
  18. attach.Name = 'Final quote- '+objOpp.Name +' '+String.valueof(Datetime.now())+'.pdf';
  19. attach.IsPrivate = false;
  20. attach.ParentId = objOpp.Id;
  21. insert attach;
  22. return null;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement