0

I've set up a autolaunched Flow, which creates a PDF based on a Quote Template. My connected APP use this Flow through the REST-API.

The output is an empty PDF with a Size of 2 KB. The same Flow, the same Input through the Workbench is successful.

It must be some kind of missing permsission, but i cannot figure it out. Any Idea why the same Call through the connected App has a different output?

The Flow itselft triggers an apex Code:

   public static void CreateQuoteDocumentFromPDF(List<Id> ids) {

    Blob renderedPDF;
    List<QuoteDocument> docs = new List<QuoteDocument>();
    if (Test.isRunningTest()) {
        for (Id id : ids) {
            renderedPDF = Blob.valueOf('Unit.Test');
            QuoteDocument doc = new QuoteDocument(QuoteId = id, Document = renderedPDF);
            docs.add(doc);
        }
    } else {
        for (Id id : ids) {
            List<Quote_Generation_Settings__mdt> quoteSettings = [SELECT Quote_Template_Id__c FROM Quote_Generation_Settings__mdt WHERE QualifiedApiName  = 'Settings' LIMIT 1];
            if (quoteSettings.size()>0) {
                if (quoteSettings[0].Quote_Template_Id__c != null && quoteSettings[0].Quote_Template_Id__c != '') {
                    String quoteURL = '/quote/quoteTemplateDataViewer.apexp?resizeAutomatically=true&summlid=' + quoteSettings[0].Quote_Template_Id__c + '&id=' + id;
                    renderedPDF = new PageReference(quoteURL).getContentAsPDF();
                    QuoteDocument doc = new QuoteDocument(QuoteId = Id, Document = renderedPDF);
                    docs.add(doc);
                }
            }
        }

    }

    if (docs != null) INSERT docs;

}

The Custom Settings is for setting the Quote Template which should be used, since QuoteTemplates cannot be searched using Apex.

0

Found the issue: The Blank Page is because of same Transaction in which the Quote was created and the PDF was generated. Solution was to mark the Function as future(callout=true)

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.