Maven Documents Template Builder is an add-on that you can install on a Google Doc, Google Sheet, DOCX, or XLSX file and use to build a template document with the data you have on Salesforce.
Please follow the instructions below to install the Template Builder add-on.
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 the Template Builder add-on on a Google Document.
Open the Google Doc that you've added to the Document Template in the Maven Documents app on Salesforce and click on the Extensions tab.
Hover over the Maven Documents item in the dropdown list and click on Template Builder.
You'll find the Template Builder work pane on the right side of the Google Document. The object 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 the 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 the Document Template in Maven Documents, the Fields section in Template Builder will now show all the fields from the two root queries that you created in the previous section: Opportunity and Sales Agent. The OpportunityLineItems query 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 will be added to the document. The fields from the Template Builder will be added in the {!QueryName.FieldName} notation, and 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 will be dynamic, meaning they will 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 to us 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 (a repeater or table element). Let's see how you can do that:
Place the cursor where you want the products to be shown. Then, in Template Builder open the Elements tab.
Select the Table element. Table iterates through records selected in the Value attribute, and for every record, in the iteration, the table row is repeated. The Variable attribute represents the current record in the iteration.
Referencing Variables inside Tables and Repeaters requires you to place # (hash sign) before and after the name of Variables.
Select the following attribute values:
Leave the Hidden attribute unselected and click Insert Element.
Now that the Table has been 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) will be the header row and will be filled with field names. As for the bottom row (row 2), you'll put Total Opportunity Amount by adding the field from Template Builder. Now, all you need to do is fill out the repeating row (row 1) with field values. Place your 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.
Select the following attribute values:
Leave the Hidden attribute unselected 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 document template, 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 following steps:
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.
Select the following attribute 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 details. 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. You'll do that in the next section, by using Button Configuration to generate documents from record pages.
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. You are going to add an expiration date to the quote. In the example, it expires 30 days after the quote (document) 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.
This will open Expression Builder.
First of all, you can see 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 your 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 the Salesforce fields within Expressions. Let's say you have the Table element that shows Opportunities for a queried Account. If an Account 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 as you usually would. On the Hidden attribute, 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 will hide the table if an 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.
As you've probably seen, expressions can also be used within elements, on all attributes which support them. If an attribute has a switch next to it - it supports expressions.
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 will do the magic for you.
Select the Include Element from the list in Template Builder.
Name the element and select the needed Source Type:
Let's say you go for the Document Template Source Type.
After the 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 Expression Builder textbox.
For the merge field option, after choosing Google Doc Source Type, select the needed field in the Source attribute
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 attribute and place the ID of the Google Doc 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 curly brackets, 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.