Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global class QuotePDFGenerator {
- webservice static String AttachPDFToQuote(string Id) {
- try {
- String quoteURL = '/quote/quoteTemplateDataViewer.apexp?headerHeight=156&footerHeight=94&summlid=0EH800000000fkT&id=' + Id;
- PageReference page = new PageReference(quoteURL);
- // Blob loadedPage = page.getContent
- // When using this method, I get "Error, Failed to load PDF document." when trying to view the PDF
- // When using `getContentAsPDF` I get a blank PDF.
- Blob renderedPDF = page.getContentAsPDF();
- QuoteDocument doc = new QuoteDocument(QuoteId = Id, Document = renderedPDF);
- INSERT doc;
- String Name = [ SELECT Name FROM QuoteDocument WHERE QuoteId =: Id ORDER BY CreatedDate DESC LIMIT 1 ].Name;
- return Name;
- } catch(exception ex) {
- System.debug('Error: ' + ex);
- return ex.getMessage();
- }
- }
- }
Add Comment
Please, Sign In to add comment