Salesforce 从流调用时,无法创建带Apex的报价PDF

Salesforce 从流调用时,无法创建带Apex的报价PDF,salesforce,apex,Salesforce,Apex,我已经创建了一个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

我已经创建了一个
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; 
    }
@InvocableMethod(label='Create Quote PDF'description='创建PDF并将其保存到Quote'
公共静态void createPdf(列表quoteID)
{
字符串quoteId=quoteId[0];
//创建pdf内容
PageReference pg=新的PageReference('/quote/quoteTemplateDataViewer.apexp?id=xxx&summlid=yyy');
//包含报价pdf的报价的文档对象
QuoteDocument quotedoc=新的QuoteDocument();
//获取Pdf的内容。
Blob b=pg.getContentAsPDF();
//分配给文档的内容
quotedoc.文件=b;
//将报价id分配给pdf应附加的位置
quotedoc.QuoteId='xxx';
插入quotedoc;
}
当我执行我的流程时,这不起作用;它将创建一个PDF并将其附加到报价中,但它将为空。有趣的是,如果我抓取这段代码并在匿名窗口中执行,它工作得很好!PDF按预期生成。如果出于某种原因从流中调用它,它看起来不起作用


您知道如何解决此问题吗?

可能的解决方案(通过SFSE)是通过异步Apex将文档生成分解为单独的事务:@davidered我使用
future
方法解决的问题是,它不会立即创建。尽管如此,我还是要试一试。@Davidred工作得很好,谢谢你的帮助!