Document Generation

Generating Documents

Once you have published templates, you can use them to generate documents from records of the Master Object for which the template was created and published. You can access details of these published templates from the CloudFiles app in Salesforce.

View Template List

To view the template list and related details, follow these steps:

  1. Go to the App Launcher in Salesforce.
  2. From the App Launcher, select the CloudFiles app.
  3. In the CloudFiles app, go to the 'Document Generation' tab.

By following these steps, you can view the list of published templates and access their details, enabling you to generate documents from the relevant records in Salesforce.

The following details are available for a published template record -

1

Template name - The name given to the template when published.

2

Source object - The Master Object for which the template is published.

3

Template Id - Unique ID assigned to each published template.

4

Version Number - The version number of the template.

Below is how the published templates look like -

Document image


The published templates will be available for document generation on the desired Salesforce Object. There are two ways to generate documents -

  1. Manual generation by LWC - The CloudFiles Doc-Gen LWC can be easily added to any object's record detail page in Salesforce. Once added, this widget will display all the published templates related to that object. Users can then generate documents in either DOCX or PDF format, which will be automatically downloaded upon generation.
  2. Automated Generation by flow actions - The CloudFiles Flow Actions can be utilized in flow builders to build to configure the automation of document generation.

We will cover both the ways of Document generation one by one below -

Manual Document Generation using CloudFiles Doc Gen LWC

In order to generate documents by CloudFiles Doc-Gen LWC, you need to add the CloudFiles Doc-Gen widget to your desired record layout. You may refer to the Document Generation Set-up to set-up the widget on your salesforce account in case, you have not added it yet.

Once the set-up is done and widget is added, follow these steps to generate a document.

  1. Navigate to the 'CloudFiles Doc-Gen LWC' on the object page.
  2. Click the drop-down menu next to the template you want to use for generation.
  3. Select 'Generate DOCX' or 'Generate PDF' for the desired document format.
  4. The document generation process takes a moment. Once the document is generated, you can download it to your system or can click ‘Copy to Salesforce Files’ in order to upload the generated document as a Salesforce File and attach it to the record in the 'Files' section.

Refer to the GIF below for visual understanding.

Document image


Automated Document Generation using Flow Actions - Overview

The CloudFiles Flow Actions can be used in Salesforce Flow Builder to configure the automation of document generation. This method streamlines the process and ensures documents are generated based on specific triggers and criteria set in the flow. For example sake, here we are using ‘Account’ object to generate an automated document populated with required details according to template, whenever an Account record is created. To achieve this we will be using two flows as described below. The detailed steps are given in the next section

Flow 1 - Record Triggered Flow

To create the Automated Document Generation, we set up a record-triggered flow that activates when a record is created. We used the template ID of a published template to generate the document using the 'Generate Document' action of CloudFiles. This action creates a CloudFiles platform event, which is pushed into the event bus and triggers the next Platform Event - Triggered flow.

Below is how this flow looks like -

Document image


Flow 2 - Platform Event - Triggered Flow

The next flow is triggered when a CloudFiles event of type 'document-generated' is published upon document generation in the first flow. After retrieving all the event details, the flow checks if the generated document belongs to the Account object. If it does, the content version details are fetched from the event data. Using these content version details, the template is populated with the relevant information, and the document is generated.

Below is how the second flow looks like -

Document image


Walkthrough Steps to Automate Document Generation Using Flow Actions

Please refer the steps below to automatically generate and attach files to a Salesforce record using CloudFiles Doc Gen actions

1 - Create a Record Triggered Flow

1 - Navigate to Salesforce Setup. Find and select ‘flows’ from Quick Find Box. Click on ‘New Flow’.

2 - Create a Record Triggered Flow for Account object, which will be triggered when an account record is created. Make sure this runs in an asynchronous path.

3 - Add the CloudFiles ‘Document Generation’ action to the flow with following input parameters. Leave rest of the configuration as is.

Document Type - It is the file format in which you want to generate the document. This could be either pdf or docx according to your preference.

Record ID - It is the record of a particular object for which we want to generate the document. In our case, it should be the record ID belonging to the Account object. Fill the field as Triggering Account > Account ID.

Template - This is the ID of the already created template we want to use for this particular record to generate the document. To fetch and store the template ID, refer to the GIF below -

Document image


After filling in the necessary input parameters, your event configuration should look like this. Save and activate the flow once everything is complete.

Document image


2 - Create a Platform Event Triggered Flow

A 'document-generated' type event will be published as a result of the action in the above flow, triggering this flow. Follow the steps below to set up the flow.

1 - Create a new ‘Platform Event - Triggered Flow’ type flow and choose Platform Event as ‘CloudFiles Event’.

2 - The flow will be triggered for every CloudFiles Event published, but we want to run the flow actions only when a 'document-generated' type event occurs. To achieve this, we will add a decision element to the flow and create a path for 'Document Generated.' Set the following condition to identify the 'Document Generated' event and add the specified resource in the path. Triggering Event > Type Equals document-generated

3 - Add a Get Event Details action and set the input value for the Event parameter as {!$Record}.

4 - To check the object type on which the document is generated we will add a decision element and compare parentID of generated document with the right object.

5 - To get the ‘Content Version’ record of the generated document follow the steps below -

Add a ‘Get Records’ element > Put object as ‘Content Version’ > Add a condition as Id Equals Outputs from Get Event Details > Document Generated > Content Version ID

Below is how the decision element looks like -

Document image


6 - We now need to attach the generated document to the record. Follow the steps below -

Add a ‘Create Records’ element > Select object as Content Document Link > Set the field values as:

  • ContentDocumentID ← Content Version from Get_Content_Version > ContentDocument ID > ContentDocument ID
  • LinkedEntityId ← Outputs from Get_Event_Details > DocumentGenerated > ParentId

Below is how this decision element looks like -

Document image


This is how you can set up the flows to auto generate documents using CloudFiles Doc Gen actions. To test the flows, please refer to the next section

3 - Test the automated document generation in action

Create a new account record, and the activated flows will trigger, resulting in an automatically generated document being attached to the record.

Refer to the GIF below to have a visual understanding of these steps -

Document image


This is how you can generate documents using CloudFiles Doc Gen, either manually or automatically.