Guest User

Untitled

a guest
Jul 16th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. global class QuotePDFGenerator {
  2. webservice static String AttachPDFToQuote(string Id) {
  3.  
  4. try {
  5. String quoteURL = '/quote/quoteTemplateDataViewer.apexp?headerHeight=156&footerHeight=94&summlid=0EH800000000fkT&id=' + Id;
  6. PageReference page = new PageReference(quoteURL);
  7.  
  8. // Blob loadedPage = page.getContent
  9. // When using this method, I get "Error, Failed to load PDF document." when trying to view the PDF
  10.  
  11. // When using `getContentAsPDF` I get a blank PDF.
  12. Blob renderedPDF = page.getContentAsPDF();
  13.  
  14. QuoteDocument doc = new QuoteDocument(QuoteId = Id, Document = renderedPDF);
  15. INSERT doc;
  16.  
  17. String Name = [ SELECT Name FROM QuoteDocument WHERE QuoteId =: Id ORDER BY CreatedDate DESC LIMIT 1 ].Name;
  18.  
  19. return Name;
  20. } catch(exception ex) {
  21. System.debug('Error: ' + ex);
  22. return ex.getMessage();
  23. }
  24.  
  25. }
  26. }
Add Comment
Please, Sign In to add comment