Generating documents by using Button Configurations in Maven Documents is pretty simple and easy to use. But there are some other options to generate your template. For example, you can do that with different types of Salesforce Flow. It may sound complicated but don't worry, we will show you the way.
We won't describe all the Flow types or their components here. We'll just show you some basic examples of using Flows to generate documents. If want to dig a little deeper in that field, here's the Salesforce trail and Salesforce documentation on Flow Builder
Here we will describe how to create and use a Screen Flow for generating documents.
Open Setup and search for Flows in the Quick Find Box.
Open Flows.
Click the New Flow button to create a new Flow.
Select the Start From Scratch option and click Next.
From the list of options,select Screen Flow and click Create.
After these steps, you will see the Flow canvas, where you'll operate with the Flow components. So let's get straight to business.
First, we need to do some prework and create a Variable that will hold the ID of the corresponding record. On the left section of the Flow Builder open the Toolbox and click New Resource.
Create the Text Variable using the screenshot below as a reference.
Now we can add Flow elements.
Click the Add "+" element between the Start and End points and select the Get Records element. With this element, we will get the ID of the record from which we are starting the Flow. We will use this information in the next Flow element. Take a look at the screenshot below to fill in the element's fields
When fields are filled in, click Done.
Once we've finished getting the needed information with the Get Records element, it's time to add the Screen element.
Give the Screen a name by filling in the Label field in the right panel and scrolling down the Components tab on the left to look at components in the Custom section.
These are the building blocks of your future Flow. Each of the components stands for the well-known functionality from Maven Documents. You are already familiar with most of them:
We recommend you use this component with the Document Template Selection in the Flow, so you can reference it and retrieve the needed data automatically.
Select the Document Template Selection component and click on it or drag it to the area under the [Flow Label] header. You should start with this component as it gives you the necessary information for the generation process. If this component is skipped, the Flow ends in an error.
Fill out the Properties form in the right panel:
You can also use the ID of the record where you run the Flow. But on this occasion, the Flow will generate the document connected to this particular record even if the generation process is started on another record.
Click Done.
You will find the added screen element with the selected component on the canvas.
Once you run the Flow, the first screen component will look like that.
You can notice that there are two Next buttons. The reason for that is having the Footer checkbox marked in the Screen Properties.
We recommend you unmark this checkbox because having two sets of buttons is confusing and using the Footer buttons can lead to improper results of the Flow.
Now, let's add a new Screen element under the Template Selection. Give the element a name, for example, "Document Generation", and select the Generate Document component. Label it as Generate_Document as well.
Notice, that in the properties fields, we used references to the Template Selection screen. That means, that the generation process will look at the result of the first screen and use this result as data.
If you would like to overwrite the values you have in the Document Template, you can manually put the needed data in the Flow component field. Take a look at the PDF Conformance Level, PDF Version, or Folder Path fields in the screenshot above.
If you use merge fields in the Folder Path field, you need to add the dollar sign $ to the name of the field as we have in the screenshot. It allows the app to separate Flow elements and merge fields during the generation process.
Click Done and check the screenshot below to compare.
In the end, we'll add one more screen to show the preview of the generated document.
If you remove the Pause/Back buttons from the Generate Document screen component consider the following: if you have the Before/After Merge preview during the generation, clicking the Cancel button in the preview leads the process to the next screen, not the previous one. In that case, the generation process will be cancelled. The corresponding Document Request and Action Request will have the Cancelled status as well.
Add a new Screen to the flow and name it. Then select the Preview Salesforce File component, label it, and fill in the File Id field.
As you can see in the screenshot above, we are referencing the Document Generation screen in the File Id field. By doing that, we are making sure, that the last screen will show us the preview of the document that is generated with the current Flow.
Click Done.
There is also an opportunity to add Action elements to the Flow. They have the same functionality as Actions that you can add to Document Solution.
Let's begin with adding the Email Preview Action at the end of the Flow. We made the custom Preview Email action to use in Flows.
While building the Flow add a new action after the Document Generation screen and search for the Preview Email action.
The next step is to select the needed values. Here you can select values you need to edit by switching the toggle and filling the corresponding field with data. We selected some core values for the Email Preview and added the necessary data.
Click Done and the action appears in the Flow.
For this Action, we will need some additional information. This time we need values from the Document Request record that is created during the Flow. It means that it's time to use the familiar Get Records element
Delete Email Preview action.
Add the Get Records element and fill in the fields as shown in the screenshot below.
Add a new Action element and in the Category section select the Maven Documents Actions category.
Click on the Search Bar and select the Delete Google File action from the list.
Fill in the required and other needed fields with values. You can use the screenshot below as a reference.
Click Done to see the created Flow on the Flow Builder canvas.
Delete the Delete Google File action.
Add a new Action element and in the Category section select the Maven Documents Actions category.
Click on the Search Bar and select the Email Autosend action from the list.
Fill in the required and other needed fields with values. You can use the screenshot below as a reference.
Click Done to see the created Flow on the Flow Builder canvas.
Delete the Email Autosend action.
Add a new Action element and in the Category section select the Maven Documents Actions category.
Click on the Search Bar and select the Field Update action from the list.
Fill in the required and other needed fields with values. You can use the screenshot below as a reference.
Click Done to see the created Flow on the Flow Builder canvas.
Delete the Field Update action.
Add a new Action element and in the Category section select the Maven Documents Actions category.
Click on the Search Bar and select the Move Google File action from the list.
Fill in the required and other needed fields with values. You can use the screenshot below as a reference.
Click Done to see the created Flow on the Flow Builder canvas.
Delete the Move Google File action.
Add a new Action element and in the Category section select the Maven Documents Actions category.
Click on the Search Bar and select the Share Google File action from the list.
Fill in the required and other needed fields with values. You can use the screenshot below as a reference.
Click Done to see the created Flow on the Flow Builder canvas.
Keep in mind, that Delete, Move, and Share Google File actions won't work with DOCX and XLSX Document Templates. As the generated file of these templates is not saved on Google Drive, it can't be deleted, moved, or shared. In this case, the Flow ends in an error.
This is how you build the Screen Flow! Now you can click Debug to check how it works. If everything is as expected then save it and click Activate. Now you can add it to the Opportunity record page as a button on the Page Layout and see the Flow in action.
As we've mentioned in the Actions article, you can execute the Copy Document to Salesforce action by embedding it in the Flow. In the instruction below we will give you examples of how to use the action as a separate component and as a part of the document generating Flow.
The Copy Document to Salesforce component can be the only one in the Flow but still give you the result you need. You will be able to place the file you've generated on the record you need. Follow the steps below to get the things going.
In the Setup settings on Salesforce, search and select Flows.
Click the New Flow button and select the Screen Flow.
On the Flow canvas, add the Action element and select the Copy Document to Salesforce action.
Fill the fields of the component with the needed information:
Currently, the Copy Document Action only supports Microsoft OneDrive DOCX files.
For DOCX and XLSX templates, the External File Id field on the Document Request record is only populated when the Save As option is OneDrive.
Save and Activate the Flow.
Now, when the Flow is saved, you can run it either from the Flow canvas by clicking Run in the top right corner, or you can create the Flow Action on the needed record and add the button with the action to the record's layout. In the second case, the Flow is executed after you click the button.
That is it! Once the Flow is executed, the file is placed in the Notes & Attachments related list on the selected record. You can also find the Document Request record for the executed action in the Document Requests tab.
Notice, that the Page Count Manage field on the created Document Request is populated with the number of pages in the used file.
For this option, you can use the document-generating Flow we've described earlier in the documentation.
Once the document generation Flow is built, add a new Get Records element after the Preview File Screen.
With this element, we will pick the External File ID from the created Document Request record, and use it in the Copy Document to Salesforce Action. Use the screenshot below as a reference.
Add the Copy Document to the Salesforce action at the end of the Flow.
Fill the fields of the component with the needed information:
Currently, the Copy Document Action only supports Microsoft OneDrive DOCX files.
This is how you can embed the Copy Document to Salesforce action into the document-generating Flow. After you run the Flow, it will generate the document, automatically get the external file ID from the corresponding field, and pass this value to the Copy Document to Salesforce action. As a result, you will get a copy of the generated file saved on the needed record with one click!
Notice, that the Page Count Manage field on the created Document Request is populated with the number of pages in the used file.
We are going to describe this action separately because it is kind of special. As we mentioned in the corresponding section in the Actions article, the Merge Files action is not available on a Document Solution but can be called by using the Flow functionality. Here, we will describe how you can use the Merge Files action in the Flow that generates the template and how to build the Flow that only merges PDF files from the Salesforce org.
Remove the Share Google File action from the Flow you've built using our Documentation.
Add a new Get Records element that will retrieve Content Versions of the needed PDF files. Use the screenshot below as an example.
Notice that the Condition Requirement should have the OR junction. That will let you retrieve several files filtered by different conditions. In our case, we will use the generated file and all the files that have 'uploaded' in their title.
It is also important to store all the records that were filtered.
The next step is to add the Loop element. We will use it to go through all the files you've collected with the previous Get Records element.
After the Loop is added it is time to group all the found files in one place. To do that we will use the Assignment element. With the help of this element, we store the IDs of all the files that we found, in one Variable.
In our case, we need to create a new Variable. You can do it right in the Variable field in the added Assignment element by clicking the New Resource option. Use the screenshot below as a reference.
Once the Variable is created and placed in the corresponding field, use the Add operator and select the ContentVersionID field from the Loop as Value. Take a look at the screenshot below.
When the needed IDs are collected and stored, you can use them as the source of data in the merging process. So we will finally add the Merge Files action to the Flow.
Fill in the Action fields as it is shown in the screenshot above and click Done.
In the screenshot below you can see how the Flow should look like if you were following our instructions.
This is the way to use the Screen Flow to generate the Template and merge the generated file with other PDFs. Save the built Flow and click Activate. Add it to the Opportunity record page as a button on the Page Layout and see the Flow in action. Once the Flow finishes you can find both generated and merged files in the Notes & Attachments section on the used record.
If you would like to use the Merge Files action in the Flow with two or more callouts, you can do it by changing advanced options. Open the respective section on the Merge Files action layout and select the Always start a new transaction option.
If you need to just merge some PDF files from Salesforce without generating any template, you can easily do it by building the corresponding Flow.
Use the instructions above as the basis. But, as you don't need the generation process, you can skip steps by adding Select Template and Generate Document screen elements and get from getting record ID to getting Content Versions.
After adding the Get Records element, select the Content Version object and define the needed filtering conditions.
Make sure that you use the exact title of the needed file, so it is fetched during the merge process. You can also sort records by the modified date. In that case, you can be sure, that the "freshest" file is used from several documents with the same name.
Use the screenshot below as a reference.
In our example, we will merge the file with the defined ID and all the files that contain defined words in their title.
Then you need to add Loop and Assignment elements to collect and group IDs of all the corresponding files.
Add the Merge Files element by filling in its fields with the needed data.
At the end of the Flow, we will add the screen with the Preview element to see the merged file when the Flow is finished.
The result of the steps above is shown in the screenshot below.
Once the Flow is finished, Save and Activate it. Add the Flow to the Opportunity record page in the form of the button on the Page Layout and run it to see the result. The result is the preview of the file on your screen and the merged file is in the Notes & Attachments section.
These two examples above are not the only ways to use the Merge Files action. You can use different types of Flows to call that action, to fit the business logic.
As you may have noticed, generating a document with the Screen Flow also requires clicking some buttons. Earlier in the documentation, we focused on generating quotes from an Opportunity record by clicking a button as well.
However, sometimes we want to avoid doing that manually and would like documents to be generated automatically. That's where the Record-triggered Flow comes in. We can generate documents from a Flow and have our quote ready as soon as a certain event happens.
Let's say that we want to have our quote automatically generated for us as soon as our Opportunity enters the Proposal/Price Quote stage. We can easily set that up in Flows. To create a new Flow:
Open Setup and search for Flows in the Quick Find Box.
Open Flows.
Click the New Flow button to create a new Flow.
We will choose our Flow to be the Record-Triggered Flow.
Click Create.
Let's now edit the Flow we just created:
On the Configure part element, Under the Select Object part, enter the object name (here it's Opportunity).
Configure the trigger so it starts the Flow every time a record is created or updated.
In the Entry Conditions part, under Condition Requirements, select the All Conditions Are Met option. Set it so the StageName has to equal Proposal/Price Quote, leave the rest of the Configure Start part as it is, and click on Done.
Press '+' to select a new element and then choose Get Records.
Input the following and click Done:
Press '+' to select a new element and then choose Create Records.
Name the element Insert new Document Request:
and input the following:
Save the Flow, and name it something along the lines of: Opportunity - Generate Document.
And the last step would be to simply activate the Flow by clicking the Activate button:
Now that our process has been activated, we can check how it works. Here, we have the GenePoint SLA Opportunity that's in the Perception Analysis stage and has products associated with it.
If we mark that stage as complete, it will move to the Proposal/Price Quote stage and that update will then trigger our Flow which will create a new Document Request.
After changing the stage to Proposal/Price Quote refresh the page and check the Notes & Attachments list and you should see that your quote has been generated.
NOTE: Document generation takes a few seconds to complete, so if your document is still not there try refreshing a few more times until it pops up.
With that, we have successfully automated the generation of our quote document using the Flow. From now on, quotes will be automatically generated for an Opportunity as soon as they reach the Proposal/Price Quote stage, and we don't have to worry about it ourselves.
If you want to learn more about automating document requests, check the Automate with Code page.
Flows can create more document requests than is the limit for synchronous document creation. For that, it is necessary to specify the Processing Type as Batch. After setting the type, it is necessary to run the Batch document creation through the Maven Documents Settings page located in the Maven Documents App. Along with just running the Batch, options on how many documents should be generated, in how many batches, and what the frequency of generation should be are also available:
After running the Batch, it is possible to stop it by clicking the button Stop Batch. Also, the settings you type in can be saved by pressing the Save Settings button. This process may take a while after which generated documents will be available in the attachments section of the record.