Tutorials
Document Generation Tutorials
How to generate a document via screen flow with runtime variables?
in this tutorial, you’ll learn how to generate a purchase order document using screen flow with runtime variables the tutorial covers how to create a template with runtime variables and then configure those variables in a flow so that users can provide input at runtime this approach allows you to generate dynamic documents that combine salesforce record data with user entered information using cloudfiles variables in the generate document (sync) docid 9davjkiyvj2zfhjw7zcvx action what to expect by the end of this tutorial, you will learn how to create a template that includes runtime variables configure a screen flow to capture user input for those variables pass the collected values into the document generation step generate a final purchase order document that merges record details with runtime inputs 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 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 1 create template with runtime variables the how to build a template (word) docid\ lrofcwxxmyxa9aiic it tutorial, provides a sample template that uses the order object along with related items from the orderitem object in this tutorial, we’ll extend that concept by adding runtime variable docid\ axlc5bzdbbimwpkbabj9 these variables allow you to capture user input at the time of flow execution and merge it into the document, alongside data coming from order and orderitem this makes it possible to dynamically generate additional content based on values provided at runtime we will create runtime variables for the following data types string – to set the document title example purchase order september 2025 double – to pass decimal values such as discount % example discount 7 5% date – to pass important dates such as the payment due date example payment due date 15 sep 2025 boolean – to control conditional logic in the template by showing or hiding specific information example display the text “this is an enterprise purchase” only when the checkbox is selected rich text area – to pass formatted text such as special instructions example note ensure purchase before quarter end steps to create a runtime variable in the word template click ' resources '; the resource manager opens up in the ' new resource ' pane, select resource type from the drop down as ' runtime variable ' enter a label , and the api name assign a value type based on your requirement string to pass the document name , create a runtime variable of type string configuration label document name api name document name value type string add the document name variable under the document title action this ensures the document title is dynamically generated at runtime double to pass the discount % , create a runtime variable of type double configuration label discount api name discount value type double add the discount into the template using insert field action date to pass the payment due date , create a runtime variable of type date label payment due date api name payment due date value type date add the payment due date into the template using ' insert field ' action boolean to control conditional logic in the template, create a runtime variable of type boolean this allows you to show or hide specific information based on a true/false value configuration label enterprise purchase api name enterprise purchase value type boolean conditional display with boolean variable type the text in your template that you want to display conditionally, for example “this is an enterprise purchase” select the text and choose insert condition from the right hand panel in the condition settings set field → {!enterprise purchase} set equals → {$globalconstant true} click insert rich text area to pass special instructions , create a runtime variable of type rich text area this allows you to include formatted content such as bold text, italic text, bullet points, or even hyperlinks in the generated document configuration label special instructions api name special instructions value type rich text area add the special instructions into the template using ' insert field ' action 2 publish template once the template is updated with runtime variables, publish it so that it becomes available for use in document generation after publishing, the template will appear under the document generation → docgen templates tab make sure to note the template id , as you’ll need it later when configuring the flow action runtime variable names (api name) are case sensitive and must match exactly when referenced in screen flow or cloudfiles assignments in the upcoming sections, we will look at how to configure runtime variable reference in flow 3 build a screen flow to generate documents dynamically, we use a screen flow in salesforce the flow serves as the bridge between user input and the cloudfiles template by adding screen elements, we can collect runtime values (like batch number, discount, or payment due date) directly from users at the time the flow runs these inputs are then mapped to the runtime variables in the template, allowing the generated document to include both salesforce record data and the additional details provided during execution navigate to setup → flows → new flow choose screen flow create a 'recordid' input variable create a recordid variable to capture the salesforce record id (order record) from which the flow is launched set its data type to text and mark it as available for input so the record id is automatically passed when the flow runs from a record page 4 include a 'screen' include a screen element to get input for runtime variables add a 'text' input string drag a text input ito the screen and label it document name and set api as vardocumentname this variable will capture the document name at runtime add a 'number' input – double drag a number input component onto the screen and label it discount % set the api name as vardiscount this variable will capture decimal values at runtime add a 'date' input – date drag a date input component onto the screen and label it payment due date set the api name as varpaymentduedate this variable will capture date values at runtime add a 'checkbox' boolean drag a checkbox component onto the screen and label it enterprise purchase set the api name as varenterprisepurchase this variable will capture a true/false value at runtime add a 'long text area' – rich text drag a long text area component onto the screen and label it special instructions set the api name as varspecialinstructions this variable will capture formatted text at runtime rich text input options you can also use any custom screen component to capture rich text input, or pass values from any custom field with rich text format into the runtime variable these values can then be printed in the generated document while retaining the formatting 5 create and assign cloudfiles variables create cloudfiles variables create variables of data type apex defined, and select the apex class as ' cldfs cloudfilesvariable ' for each screen input we create these variables because the input fields captured in the screen flow (document name, batch number, discount, etc ) need to be mapped to cloudfiles runtime variables by assigning these inputs to apex defined variables, the values can be passed into the generate document (sync) action create one variable for each input field in your screen flow cfvardocumentname → for document name (string) cfvarbatchnumber → for batch number (integer) cfvardiscount → for discount % (double) cfvarpaymentduedate → for payment due date (date) cfvarspecialinstructions → for special instructions (rich text area) assign values to the cf variables the cloudfiles variable has key and valuestring as parameters, which must be assigned using the assignment element in the flow key is the api name of the runtime variable as defined in the cloudfiles template valuestring is the actual value you want to assign and pass add an assignment element in your flow for each input and map as follows cfvardocumentname key → document name cfvardocumentname valuestring → {!vardocumentname} cfvarbatchnumber key → enterprise purchase cfvarbatchnumber valuestring → {!varenterprisepurchase} cfvardiscount key → discount cfvardiscount valuestring → {!vardiscount} cfvarpaymentduedate key → payment due date cfvarpaymentduedate valuestring → {!varpaymentduedate} cfvarspecialinstructions key → special instructions cfvarspecialinstructions valuestring → {!varspecialinstructions} create a collection variable of data type apex defined, and select the apex class as cldfs cloudfilesvariable this will be passed as input for generate document (sync) docid 9davjkiyvj2zfhjw7zcvx action add all the above variables into this collection 6 adding destination the generate document (sync) docid 9davjkiyvj2zfhjw7zcvx 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 save documents to external storage to store documents in external storage such as sharepoint , google drive , etc , you need to configure the library , drive id , and folder id refer to the destination section in generate document (sync) docid 9davjkiyvj2zfhjw7zcvx for more details 7 add the 'cloudfiles generate document (sync)' action in the flow, click + and select action search for and choose cloudfiles generate document (sync) fill in the following input parameters destination provide the previously created destination variable to specify where the generated file will be stored you can store it either in a salesforce record or in an external storage location (such as sharepoint or google drive) 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 enter docx for finalized, non editable documents enter pdf if the document will need further editing record id pass the {!recordid} 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 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 parameters section of generate document (sync) docid 9davjkiyvj2zfhjw7zcvx 8 activate and test the flow save and activate the flow add flow to record page to allow users to generate documents directly from a record page, add the flow component into the record page navigate to the object manager in salesforce setup select the order object go to lightning record pages → edit the desired page drag the flow component onto the page layout in the properties panel, select your newly activated flow save and activate the page users will now see a flow section on the record page to generate documents with instructions testing once the flow is added to the order record page, it will now display the screen with inputs for document name, batch number, discount, payment due date, special instructions enter the details click 'next' the generated document(s) will then be saved in the order's notes & attachments it will display the runtime values entered by the user along with the standard order details 9 output parameters the cloudfiles generate document (sync) action provides immediate outputs, accessible in the flow’s all resources it provides the following output parameters document – id, driveid, library, name, path, type content version id document name download url preview url for more details on these parameters, refer to the output parameters section of generate document (sync) docid 9davjkiyvj2zfhjw7zcvx