Signature
global static void generateDocument( List<Types.DocGenRequestInput> payloads, String runAs )
Parameters
| Parameter | Description | |
|---|---|---|
payloadsList<Types.DocGenRequestInput> |
required | One entry per document generation request. See Types.DocGenRequestInput. |
runAsString |
optional | Username to attribute the operation to; usually a static value such as 'integrationUser'. |
Return Type
void
Example
cldfs.DocGenParams dcp = new cldfs.DocGenParams(); dcp.PdfViewPassword = 'admin'; dcp.PdfOwnerPassword = 'superadmin'; dcp.LockPdf = true; dcp.AllowPdfPrinting = true; dcp.AllowFillingPdfFormFields = true; cldfs.Types.DocGenRequestInput docGenInputs = new cldfs.Types.DocGenRequestInput( '681b4169c697ffdc2aab2731', new Map<String, String>{ 'userId' => '005dL000008FbqgQAC', 'recordId' => '003dL00000YsapJQAR'}, 'pdf', new cldfs.Resource( '68887db5ef0b3ca7534dbbd5', 'folder', null, 'cloudfiles', 'workspace' ), dcp ); List<cldfs.Types.DocGenRequestInput> payload = new List<cldfs.Types.DocGenRequestInput>{ docGenInputs }; cldfs.Client.generateDocument( payload, 'integrationUser' );
Document Generated eventAfter the file is successfully generated, a Document Generated platform event is published. You can use this event as a trigger in Apex or Flows to perform your next steps.
Creating a Document Packet from Apex
Client.generateDocument does not take packet settings. To group the generated document into a Document Packet from Apex, call the Flow action class cldfs.GenerateDocument.execute and set packetSettings on its FlowInput. Each input produces its own packet.
cldfs.GenerateDocument.FlowInput input = new cldfs.GenerateDocument.FlowInput(); input.templateId = '681b4169c697ffdc2aab2731'; input.documentType = 'pdf'; input.recordId = '003dL00000YsapJQAR'; cldfs.GenerateDocumentPacketSettings packetSettings = new cldfs.GenerateDocumentPacketSettings(); packetSettings.enabled = true; // approvalRequired defaults to true. Set it to false to send without review. input.packetSettings = packetSettings; cldfs.GenerateDocument.execute( new List<cldfs.GenerateDocument.FlowInput>{ input } );
Call it from synchronous Apex. From Batch Apex or a future method, use Generate Document (Batch), which queues its own work.