首页 > 解决方案 > 从流调用时无法使用 Apex 创建报价 PDF

问题描述

我创建了一个InvocableMethod从我的流中调用的。此方法只是创建一个报价 PDF 并将其附加到报价中。此方法如下所示:

@InvocableMethod(label='Create Quote PDF' description='Creates a PDF and saves it to the quote.')
public static void createPdf(List<string> quoteIds)
    {
        string quoteId = quoteIds[0];

        //Create pdf content
        PageReference pg = new PageReference('/quote/quoteTemplateDataViewer.apexp?id=xxx&summlid=yyy'); 

        //Document object of quote which hold the quote pdf
        QuoteDocument quotedoc = new QuoteDocument(); 

        //Get the content of Pdf.
        Blob b = pg.getContentAsPDF() ;

        //content assign to document
        quotedoc.Document = b;

        //assign quote id where pdf should attach
        quotedoc.QuoteId = 'xxx';

        insert quotedoc; 
    }

当我执行我的流程时,这不起作用;它将创建一个 PDF 并将其附加到报价单上,但它将是空白的。有趣的是,如果我抓住这段代码并在匿名窗口中执行,它就可以正常工作!PDF 按预期生成。如果出于某种原因从 Flow 中调用它,它似乎不起作用。

知道如何解决这个问题吗?

标签: salesforceapex

解决方案


推荐阅读