Guest User

Untitled

a guest
Jan 22nd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. public PageReference savePdf() {
  2.  
  3. PageReference pdf = Page.PdfGeneratorTemplate;
  4. // add parent id to the parameters for standardcontroller
  5. pdf.getParameters().put('id',parentId);
  6.  
  7. // create the new attachment
  8. Attachment attach = new Attachment();
  9.  
  10. // the contents of the attachment from the pdf
  11. Blob body;
  12.  
  13. try {
  14.  
  15. // returns the output of the page as a PDF
  16. body = pdf.getContent();
  17.  
  18. // need to pass unit test -- current bug
  19. } catch (VisualforceException e) {
  20. body = Blob.valueOf('Some Text');
  21. }
  22.  
  23. attach.Body = body;
  24. // add the user entered name
  25. attach.Name = pdfName;
  26. attach.IsPrivate = false;
  27. // attach the pdf to the account
  28. attach.ParentId = parentId;
  29. insert attach;
  30.  
  31. // send the user to the account to view results
  32. return new PageReference('/'+parentId);
  33.  
  34. }
Add Comment
Please, Sign In to add comment