Maven Documents Template Builder is an add-on that you can install on a Google Docs, Google Sheets, DOCX, or XLSX file and use it to build a template document with the data you have on Salesforce.
Go to workspace.google.com/marketplace/app/maven_documents/430563853893 and click Install.
Click Continue in the appeared message.
In the opened window, select the Google account you want to use.
Check out the listed permissions by clicking the "(i)" icon and then clicking Allow.
Read the information message and click Done.
After you follow these steps, you can create your template using Google Docs and use the "Template Builder" add-on.
Building the template begins with running Template Builder on a Google Document.
Open the Google Docs that you've connected to Document Template in Maven Documents and click on the "Extensions" tab.
Hover over Maven Documents in the dropdown list and click on Template Builder.
You'll find the "Template Builder" work pane on the right side of the Google Docs. Objects and fields from the query that you built in the "Query Builder" tab are reflected in Template Builder.
Before you start building the template, let's have a glance at what we call the Template Builder's work pane.
The "{} Fields" tab.
Here you will find objects and fields you added to the query in Document Solution. All the objects and fields can be inserted into the document with one click.
The "</>Elements" tab.
Here you have a picklist with the elements that could be inserted and used in the document. For detailed information on every element, you can check the "Google Docs Elements" reference page.
The "fx" or "Expression Builder" tab.
Expression Builder lets you create expressions (similar to formula fields in Salesforce) without needing a formula field directly on your document. More on how Expression Builder operates can be found in the corresponding sub-section. You can also read more about expressions and their syntax on the "Expressions" page.
The "Refresh Nodes" button.
This button serves two purposes:
In Google Docs, you can build your templates using everything that they have to offer. However, Maven Documents allows you to put the Salesforce data in the document, and that's what Template Builder is used for.
After successfully adding the document ID to Document Template in Maven Documents, the "Fields" section in Template Builder will now show all the fields from the root queries that you created in the previous section. The "OpportunityLineItems" query's fields are not available yet, because their availability depends on the context.
If the fields are not showing, click the "Refresh" button.
Now, all you need to do is click on the field you want and it is inserted in the document. The fields from Template Builder are shown in the {!QueryName.FieldName} notation. You can use that notation to add the fields manually but in most cases, Template Builder is the easier option.
Now it's time to add some fields to your quote document. Let's see how you can do that:
Pretty simple, right? All the fields you've put using Template Builder or manually in the "{!QueryName.FieldName}" notation are dynamic. It means they depend on the results that the query returned.
You need to show the information about Opportunity's products from the "OpportunityLineItems" sub-query. For a sub-query to be available in Template Builder, you need to be in a specific "context". Sub-queries can only be accessed from "inside of an element" that belongs to its parent query (the "Repeater" or "Table" Element).
Let's see how you can do that:
Place the cursor where you want the products to be shown. In Template Builder, open the "Elements" tab.
Select the "Table" Element. Table iterates through records selected in the "Value" parameter, and for every record, in the iteration, the table row is repeated. The "Variable" parameter represents the current record in the iteration.
Referencing variables inside Tables and Repeaters requires you to place the "#" (hash sign) before and after the name of variables.
Put the following values in:
Leave the "Hidden" parameter as it is and click Insert Element.
Now, when the Table is inserted, you need to modify a few things.
Since the Table has 4 columns, each column is used for one field from the product. The first row (row 0) is the "header row" and is filled with field names. As for the bottom row (row 2), you put "Total Opportunity Amount" there by adding the field from Template Builder. Now, all you need to do is fill in the repeating row (row 1) with field values.
Place the cursor inside any cell of the Table and click the "Refresh" button to get the fields from the "oli" variable in Template Builder. Then insert those fields into their corresponding cells in the middle row. The Table should look as displayed in the previous screenshot (point 3).
On the second page of the template, you will be adding some additional content related to the terms and conditions. You can use the standard features of Google Docs editor to edit your content. Using Template Builder, you will add a few placeholders to dynamically populate the Account Name and delivery period.
In the second paragraph, for example, you can add a hyperlink that points to the privacy policy related to the Opportunity. First, such a field should be created in Salesforce.
To insert the "Link" element inside the document, follow the next steps:
Place the cursor in the text where you would like to insert the link and click the "Refresh" button in Template Builder.
Select the "Link" element.
Put the following values in:
Leave the "Hidden" parameter untouched and click Insert Element.
In the body of the inserted element, type the text that you would like to display as a link.
On the third page of the template document, you will add payment details such as company name and address. In the "Payment Details" paragraph, you can write any specific information according to your quote.
You can also add a payment code that can be used directly from mobile banking applications. To do this, you can use the "Code" element. But, again, don't forget to create the corresponding field in Salesforce, filled with the content required by PDF417 standard for the code to work.
Insert the payment code following the instructions:
Place the cursor in the document where you would like to insert the code and click the "Refresh" button in Template Builder.
Select the "Code" element.
Use the following values:
Leave the remaining attributes empty and click Insert Element.
You are left to configure the last page of the "Sales Quote" template. This page will contain customer contact details, taken from the "Opportunity Contact Roles" and "Sales Agent" queries.
To insert the customer contacts you can use the already-known "Table" element:
When the table is inserted, fill its cells with the needed data.
This is what the template page looks like:
Now, that you have the Template, you can move on to the final step in the process, and that is to finally generate the document. But to do that, you first need to set up "Button Configuration".
Expression Builder lets you create expressions (similar to formula fields in Salesforce) without needing a formula field. You don't have to build formula fields which are only going to be used on your documents. Instead, you can create them directly in the document!
Here are a few examples of what you can do using Expressions and Expression Builder:
You can read more about expressions and their syntax on the "Expressions" page.
Let's see how you can create a simple expression and add an expiration date to the quote. In the example, it expires 30 days after the quote has been generated.
Place the cursor where you want your date to be inserted, and follow the next steps:
Open Expression Builder from the sidebar.
Click on the icon in the bottom left of the expressions input field to open Expression Builder.
First of all, you can find all the available functions in the "Select function" menu. The first dropdown menu filters functions by categories (date, number, string, etc.), and the second dropdown menu contains filtered functions you can use.
You can also insert Salesforce fields into expressions by using the dropdown in the "Insert field" menu (an arrow (>) next to a field suggests that it's a relationship field - e.g. Account > Contact > ...).
Before inserting the function or a field, verify that you've selected the text you want to replace in the text field below.
From the Select function menu, choose Date and then choose addDays. Click Insert.
You are going to replace DateTime in the expression with the current date (which is a function). From the "Select function" menu, choose Date, then Now.
Select DateTime in the text field below. Click Insert. This will replace DateTime with the "now()" function.
Replace NumberOfDays with 30.
Click Insert Expression. This inserts the expression back into the "Expression Builder" view. Click Insert Expression to insert it into the document.
Now, let's see how you can use Salesforce fields within Expressions. Let's say you have the "Table" element that shows Opportunities for a queried Account. If an "Account" record has no Opportunities you wouldn't show that table. Let's see how you can show/hide the table using the expression:
Start creating the "Table" element. For the "Hidden" parameter, click the switch to enable expressions.
Click in the bottom left of the input field to open Expression Builder.
In the "Select function" menu, select array, then select isEmpty. (Again, you need to hide the Table if the Account has no Opportunities). Insert the function.
You now have to replace Array with the array field. From the "Select field" menu, choose Account > (the arrow next to it suggests it's a relationship field), then select Opportunities (not a relationship, this is the actual array field you want).
Select Array in the text field below. Click Insert to insert the field into the text field.
Click Insert expression to insert it into the "Table" element.
You can use Expressions on all Template Builder Elements that have parameters with the respective toggle.
That's it! You can now create more complex expressions which fit your needs. You can always read more about expressions on the "Expressions" page.
Imagine the situation, when some other documents already have the table or another element that you can use in the template. You can easily have this building block in your document by inserting it from another file.
There's no need to replicate it from scratch: the "Include" element can do the magic for you.
Select the "Include" element from the list in Template Builder.
Name the element and select the needed Source Type:
You can use a merge field that holds the necessary ID of the Google Docs.
Let's say you go for the "Document Template" Source Type.
After Source Type is selected, choose the template from the picklist in the "Source" field.
As you noticed, the "Element Name" field appears after the template is selected.
Pick the needed element and Insert it into the document.
In the screenshot below you can see what the element's body looks like.
If your choice is Google Doc, you can use a merge field that holds the necessary ID or you can switch the toggle next to the Source field and enter the ID manually in the "Expression Builder" textbox.
For the merge field option, after choosing the "Google Doc" Source Type, select the needed field in the "Source" parameter.
After you insert the element, it is going to look like in the screenshot below.
If you want to insert the ID manually, switch the toggle next to the "Source" parameter and place the ID of the Google Docs in the "Expression Builder" text box.
You can find the ID if you do the following:
After you insert the element with the manually added ID, you need to remove the braces, the exclamation point, and the dollar sign that wraps up that ID.
Once you generate the document, it has the selected element or the whole content of the chosen file.
If you want to see what the actual data will be available on your Document Template, feel free to use the "Playground" tab. It can also serve as a means to debug the Flow when things aren't going as they should be.
Try changing the Locale definition in your settings, for example, and see how data changes.