Tutorials
Document Generation Tutorials
How to generate a document via automation (Record Triggered)?
in this tutorial, you’ll learn how to automatically generate a document when a salesforce record meets specific criteria, such as when a field is updated using a record triggered flow after creating and publishing a template (see the how to build a template (word) docid\ lrofcwxxmyxa9aiic it tutorial), you can configure salesforce flow to generate documents automatically whenever the defined trigger condition is met what to expect by the end of this tutorial, you will know how to set up a record triggered flow in salesforce to automate document generation optionally define a destination for storing the generated document add and configure the generate document docid\ qfdwhv81mxgwsly7nppsc action in the flow test and validate that documents are generated automatically when a record is updated tutorial video refer to the quick video if you would like to have a visual guide for this tutorial read on if you prefer textual content video will be added soon 1 prerequisites install cloudfiles in salesforce cloudfiles is available on the salesforce appexchange and can be installed using the standard app installation process check out installation docid\ aw06gffsiiq qdp1fkgcj and configuration docid\ zgbv7ll pzzzopel4 7up guides to set up your account and user access doc gen templates ensure that the templates published for the object are listed under the document generation tab → docgen templates locate the template id for the template you want to use and note it down, as you’ll need it as an input in your flow action 2 create a record triggered flow since we’re using a purchase order template that is published for the order object, set the order object as the trigger for the flow use the status field as the triggering criterion, so the document generation starts automatically whenever an order’s status changes to purchased this is how the final flow looks like the details of the flow are given below 1 choose record triggered flow for the ‘order’ object navigate to setup → flows in salesforce click new flow → select record triggered flow set the object to order define the triggering criteria when status is marked as purchased select optimize flow as actions and related records add asynchronous path 2\ adding destination (optional) the generate document flow action requires destination parameters if you want to attach the generated document to a specific salesforce record or store it in external storage let's store the document in the notes & attachments section of the order record if you don’t define a destination, the generated document will be stored by default in the salesforce content library steps to configure destination create an apex defined variable of apex class cldfs resource to save in order's notes & attachments, assign the following fields library set to salesforce id set to the record id of the order record to store in external storage such as sharepoint, gdrive, etc when using cloudfiles with the cloudfiles | document management & sharing platform assign the following fields to define the external storage location library specify the library name drive id specify the id of the connected drive id specify the id of the folder or location within the drive you can assign the above fields either manually (by referring to the metadata details from content library docid\ wtj62wux2a6hgfwvpm4ij ) or by using the get connected folder docid iq8rljf2ne8sx0 iuu action to populate the fields from the action output 3\ add the “cloudfiles generate document” action in the flow, click + and select action search for and choose cloudfiles generate document fill in the following input parameters destination → provide the previously created destination variable to specify where the generated file will be stored, either in a salesforce record or in an external storage location if left blank, the file will be saved to the salesforce content library by default document type → select the format for your output file, such as docx , or pdf for example, choose pdf for finalized, non editable documents, or docx if the document will need further editing record id → pass the {!$record id} from the triggered record this tells the action which salesforce record to use as the data source for generating the document template id → enter the 24 digit cloudfiles template id of a published template this ensures the correct template is used for document generation, so that the output is formatted and populated as intended in this example, a variable (templateid) is created to store the template id you can also use the parameters input to configure additional settings for the document, such as password protection, locking, or printing permissions to know more, refer to the input parameters section of generate document docid\ qfdwhv81mxgwsly7nppsc generate multiple documents with batch action you can also generate multiple documents with different templates using the generate document (batch) docid\ xahb umkpvgfm3k4ycbdp action to do this, you’ll need to create both individual and collection apex defined variables of the class cldfs generatedocumentflowinput within the flow configure each variable’s fields with the required configuration values (e g , template id , destination , and record id ) just as you would for a single generate document action next, add all the individual variables to the collection variable finally, pass this collection variable into the action’s inputs parameter 3 activate the flow save the flow and activate it test the flow by navigating to an order record that contains a list of order items update the status field to approved the document will then be generated in the backend and stored in the notes & attachments section refresh the page to view the generated document 4 output parameters the cloudfiles generate document action operates asynchronously, meaning it does not provide immediate outputs after execution asynchronous document generation after the action runs, a document generated docid\ mmtfv4zzddn2tgrwgszbu cloudfiles event is published there is no direct confirmation or result data immediately available you can use the document generated docid\ mmtfv4zzddn2tgrwgszbu event to initiate other flows or automate additional actions