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?

2
  • 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
    Commented Feb 10, 2017 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. Commented Feb 11, 2017 at 23:58

1 Answer 1

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
  • 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 Commented Feb 11, 2017 at 23:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .