Generate Documents in Batch Invocable Apex Action

The April '24 release includes extended SDK functionality, enabling batch document generation processes that weave seamlessly into Salesforce workflows. Like the other capabilities offered through the S-Docs SDK, the batch method provides methods to simplify the process of creating documents can be configured in many contexts. More detailed information on the Batch SDK method can be found in the S-Docs Software Development Kit (Documents SDK).

Configure Generate Documents in Batch with Flow Builder

The following documentation details how to set-up and invoke the Generate Documents in Batch Apex Invocable managed action via a Salesforce screenflow. If you would like to a more automated selection experience, replace the Screen element in the following example with two Get Record elements configured to gather the Object and S-Docs Template records.

Create a Salesforce Flow

Create a new Salesforce flow to utilize the Generated Documents in Batch Apex Invocable.

For User Interaction

If you want users to interact and choose records for batch generation:

  • Add a Screen element after the start element in your flow.
  • Drag and drop a Multi-Picklist component into your screen.
  • Choose: Let users select multiple options
  • Select the component type: Checkbox Group or Multi-Select Picklist

Create a choice value:

  • Choose ‘New Choice Resource’ > Resource Type: Record Choice Set > Select object
  • Set filter and sort criteria as needed.
  • Choose a choice label, typically the name of the selected object record.
Important: Set the choice value as the record ID associated with the object record(s) for batch document generation.

Selection of S-Docs Templates

Similarly, add another Multi-Picklist component into your screen for selecting S-Docs templates. Follow the previous steps but select the S-Docs template object for the New Resource:

Create two flow collection variables to assign your record choice sets to:

For Object Records:

  • Choose 'New Resource' > Variable:
  • Enter API name
  • Data Type: Text
  • Check Allow multiple values (collection)

For S-Docs Templates:

  • Choose 'New Resource' > Variable:
  • Enter API name
  • Data Type: Text
  • Check Allow multiple values (collection)

Resources menu in Salesforce flow builder.

Verify Setup:
  1. After completion, there should now be two (2) record choice sets and two (2) collection variables resources available in your flow.
  2. Each resource will contain corresponding variables to your object records and S-Docs Templates.





Please note that your configuration may vary if you used different API names for your elements/components. This example assumes batch generation for the Account object.

Assign Choice Sets to Collection Variables

Create an Assignment element after the screen element to assign your choice sets to collection variables.

Inside the assignment element:

  • Assign the collection variables created in step #3 to Screen Components configured for multi-selecting record values (checkbox group or multi-picklist).
  • Create two entries:
      • Variable: Use the Object and S-Doc Template collection variables
      • Operators: Add
      • Value: The screen component multi-select picklist or checkbox group configured in the first screen element
  • Match records to records and S-Docs templates to templates.

Assign Variables Configuration menu in Flow Builder

Invoke Batch Document Generation

Create an element to invoke the Batch Document Generation S-Docs apex action.

  • Choose Action > Type > Apex > Generate Documents in Batch
  • Label the API
  • Map the Base Record IDs as your collection variable for records
  • Map the Template IDs as your collection variable for template IDs
  • Batch size automatically defaults to 5. Adjust if necessary, considering Salesforce governing limits

Final Display Screen (Optional)

Create a final display screen to notify the end-user that the batch documents have been queued for completion.

Review and Navigation

After invoking, the batch job can be viewed by navigating to Setup > Apex Jobs

Final Flow Setup

Final Batch Generation Flow Setup

Tags: , , , ,

Was this helpful?