2

To Be more explicit (Edit 12/1/17): Is there an API to create Standard Quote PDF from standard quote template? It would appear not. So if not is there an Apex method to create standard quote pdf with templateId? If there is an apex method then we would build a custom API.

Original Post: We are creating the Quote data with the soap API happily. The quote is a "final quote" no need to be changed and hence while we are creating the quote we might as well generate the pdf and save it below the Quote. Or worst case retrieve it at the end of the generate process and then store wherever we please. Or do we need to build a web service within salesforce to handle the request? This may not even be possible, i.e. apex may not offer this either.

The key question is: Is there an API to create Quote PDF?

  • 1
    You can generate one via Visualforce, and the PageReference class has a getContentAsPdf method that will allow you to save it as an attachment. Not clear from your question if that's what you're looking for. – Adrian Larson Feb 10 '17 at 3:05
  • Yes we can do that, you are right so I updated the question. and upvoted your comment. I was asking if there is a way to use standard quote to PDF feature. We have visualforce as a backup plan. – NZ Dev Feb 11 '17 at 23:58
3

You can build a REST API in SFDC for this and insert a quote Document Record .

A Quote document record will need a document or a pdf and to generate blob data for PDF you may try using a simple VF and then use pagereference to get content .

@RestResource(urlMapping='/GenerateQuotePDF/*')
 global with sharing class GenerateQuotePDFController {
 @HttpPost  
  global static QuoteDocument generatePDF(String quoteId, String templateId) {
    String quoteURL = 'URL of your VF PAGE';
    PageReference pageReferenceForPDF = new PageReference(quoteURL);
    QuoteDocument newQuoteDocument = new QuoteDocument();

    //Because Methods defined as TestMethod do not support getContent call, we have to add a condition 
    Blob renderedPDF = !Test.isRunningTest() ? pageReferenceForPDF.getContentAsPDF() : Blob.ValueOf('dummy text');
    newQuoteDocument.Document = renderedPDF;
    newQuoteDocument.QuoteId = quoteId;
    insert newQuoteDocument;
    return newQuoteDocument;
  }
}

Remember to check permissions of the Page , classes and object access and use workbench to test the result

  • 1
    Not exactly the answer I was looking, but my question was not specific enough. But your answer was very good and lots of effort so I up voted. CHeers – NZ Dev Feb 11 '17 at 23:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.