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 go to the app launcher in salesforce from the app launcher, select the cloudfiles app 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 template name template name the name given to the template when published source object source object the master object for which the template is published template id template id unique id assigned to each published template version number version number the version number of the template below is how the published templates look like the published templates will be available for document generation on the desired salesforce object there are two ways to generate documents 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 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 lwc docid\ xyg vbcumwrdubf2sgsyh 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 navigate to the 'cloudfiles doc gen lwc' on the object page click the drop down menu next to the template you want to use for generation select 'generate docx' or 'generate pdf' for the desired document format 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 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 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 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 accoun t > 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 after filling in the necessary input parameters, your event configuration should look like this save and activate the flow once everything is complete 2 create a platform event triggered flow a ' document generate d' 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 docid\ cfegghvnwso7bcxyevrr 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 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 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 this is how you can generate documents using cloudfiles doc gen, either manually or automatically