Author Archive

Create URL field in document action

Steps to create URL field to save Google Doc URL to base object record (using Opportunity object for this example):

1. Go to Setup

2. Customize “Opportunity” object

3. Create New Custom field

4. Field type is URL (Label field Opportunity Doc URL or something unique)

5. Click through steps to save new field and then copy API name, should look like Opportunity_Doc_URL__c

6. Go back to document action and paste this API name (without quotation or merge field brackets around it) into field labeled “Save URL to Salesforce Field.”

7. Now go back to example Opportunity record to click custom button to merge document

8. After document is generated, the URL field will be populated on record.

9. Click URL link to edit document from opportunity record which will display in new window

10. Once edits are completed, you can then download as PDF and attach to record or follow steps to create a custom button or link with a formula that would include the google doc id and then parameters at the end to export and download as a PDF.

11. If you want to email a link to your google doc for PDF download, you can review this article.


  • This feature cannot be used with document action feature to “auto delete google doc after merge” as you need to keep the URL in order to access it.
  • This feature can only work if 1) User generates document manually or 2) User generates document using Process Builder or Batch Mode.
    • Using Apex method to generate document will not update field defined in rsdoc__Save_in_Field__c. This will need to be done manually in the Apex code.


Generate a document and then edit it

Use Case: If you want to generate a document then edit it before sending it or downloading it there are a few options our App Expert Team recommends:

  1. First thing to consider is if you want to edit it in Google Docs which is great because its all cloud based and the field remains current with every edit and you can easily collaborate with other coworkers. This would be our recommended process. The other option is to just download the file in Word, then open it in word, and work with it from Word to save as a PDF manually.
  2. You should configure your Document Action to generate the Google Doc only and not output to PDF. Configure it to save the google doc URL to a text field that you should create on your object (see this article for more information on how to create this URL field). Create the button to say something like “Generate Document” since this button/action is all about just generating the google doc, not sending it.
  3. Once you have the google doc URL saved in the field, then without anything else you could easily just click the link in that field from the page layout which will open the doc in google docs. Then you can edit it from there. When finished just close it because all changes made are saved in real time on google docs. And the link to that google doc always remains and always current.
  4. Optionally you could add a formula field or visual force section to embed the google doc directly into your page layout so you can always and immediately see the google doc and edit it right from Salesforce. See this article if would like to learn how to embed the google doc into your page layout.

A good solution is also to provide an if statement to only show this section IF there is a google doc URL populated in your field. You would just use standard embed code and reference the google doc URL to embed from that URL. See this article for an example formula of that gets the google doc id out of the full URL.

To send the completed document you have some options:

If you are planning to email the document, you can merge the google doc URL field into a link in your email template to send a link to the google doc.

Or you can create a formula field that can create a URL to link to the google doc that you can send by email but will export to PDF upon clicking it. See this article for more information on this option.

If you would like help on implementing this process, we offer premium app support.

Embed Google Doc into page layout

  1. First you need to save the merged google document URL to a field on your object first (see this article for how to create Google Doc URL Field).
  2. Then you need to create a visual force page and an apex controller extension. The page must use the object controller you want to embed on. The visual force page code should include the iframe code like: <apex:iframe src=”” scrolling=”true” id=”theIframe”/>.  Salesforce includes standard controllers for all standard and custom objects you can use.
  3. And you would replace the URL there with the field that contains the full URL of the google document that is on the object. You can also add to the iframe code to specify more things like width and height. Read more here:
  4. So you can simply create a Visual Force Page under setup with some code like this for example for the standard Work Order object:
    <apex:page standardController="WorkOrder">
      <apex:iframe src="{!workorder.Google_Doc_URL__c}" scrolling="true" id="theIframe"/>
  5.  Then you edit the standard page layout, create a new section on your layout with one column and click on visual force pages available and drag the one you created into the page layout and specify how high you want it.

Conditional Section Merge Using Template Builder


If you want to merge one or more sections onto your generated document based on a condition of a checkbox or formula field, you can do this using the section merge feature in the template builder. It is also possible to have one checkbox field that refers to multiple conditional merge sections in template. The section merge feature also makes it possible to create a conditional page break in your template.

  1. Conditional Merge Based on a Checkbox Field
  2. Conditional Page Break
  3. Conditional Merge Based on a Formula Field
  4. Multiple Conditional Section Merge

Conditional Merge Based on a Checkbox Field

The conditional merge feature allows you to merge sections of text into your document based on the value of a standard checkbox field (true or false). As an example, a sales rep could use the conditional merge feature to easily control whether to include or not include a “Special Terms” section in a contract document attached to an Opportunity record. To do this, they would create a checkbox field on the Opportunity object called “Special Terms”. If on the Opportunity record this checkbox field were checked (true), then this additional agreement section would merge onto the template. If this checkbox field were not checked (false), then this agreement section would not merge onto the document.

There will be a start and end to each conditional merge section that you will need to mark with tags. The template builder will generate the tags for you as part of your merge field code that you copy and paste into the document. Your conditional merge section start and end tags should be on their own line in the template. After the merging of start/end conditional section is completed within generated document, these tags and lines will be removed from the document so you will not have that extra space in document. Note that if you have a conditional merge section end tag at the end of the document template, you must add one extra line below that tag so the conditional end section end tag is not the last line of the entire document.

See the following steps to setup your conditional merge sections:

  1. Select the related checkbox field from in embedded template builder. For this example, we are using “Special Terms”.                                                                                                                                                                                                          
  2. Once you type your section name, then click on “Start of Section” to the right next to your section name and it will modify the merge field code to: {!Opportunity.Special_Terms__c[SECTION_START:Special Terms]}
  3. Copy this merge field code and paste it where you want the section to start on your template.
  4. Now go back to Section and select from drop down “End of Section” and copy the updated merge field code: {!Opportunity.Special_Terms__c[SECTION_END:Special Terms]}. 
  5. Copy this merge field code and paste it where you want the section to end on your template. 
  6. Then type in any information you would to show on document (for our example this would be the verbiage from the “Services Agreement”) or you could place a merge field inside of section that you would want to display if value is true.

Example conditional “Special Terms” section with START and END tags:

Note: If you are placing the Section End merge field at bottom of your template, this may cause “Read Time Out ” error with Google script and you can add an empty new line below the merge field to resolve so the merge field is not the last line in the template.

Conditional Page Break

You can create a page break using the conditional section merge feature as follows:

[begin conditional section]
<<add page break here>>
[end conditional section]
Note in the placement of the page break after the start of the conditional section:
This conditional page break ensures that, if the conditional section merge occurs, there will be a page break prior to the text within that conditional section:

Note: Conditional sections are currently not supported in related lists (tables).

Conditional Merge Based on a Formula Field

If you would like to merge conditionally without using a checkbox field, then you can create a formula field that is checkbox type and build that formula logic based on any field available to result in a true or false value. To use any logic you want, including a picklist, you can create a formula field that results in a checkbox as in true/false and put your if statements in the formula looking at the picklist field. such as If(ispickval, field, “value”,true, false).

For example, you could create a conditional merge section based on a formula field on an Opportunity record to merge ONLY if there is at least one product related to the Opportunity.

  1. Create the section and content on template builder.
  2. Create a formula field with the type as checkbox on the object merging from such as Opportunity.  The formula field in our use case could be called “Line Items Exist”.  This formula would have an IF statement to check whether the record has at least one product related to the opportunity, then return true or false.
  3. Go to the template builder and now select the new formula field just created.
  4. Check the box to make that a conditional section.
  5. Copy that merge field code to place the starting of the section at the beginning of the section, and the end at the end of the section.

Multiple Conditional Section Merge

If you would like to have one checkbox field that refers to multiple conditional merge sections in template, you can see this use case article for more detail.

Merge Images Into Your Template

A5 Documents allows you to dynamically merge images into your Document Action template using a text or formula field that provides a URL to a publicly available image (supported image types include jpg, jpeg, png, gif). The URL of the image can be copied from publicly available sources, including a Document attached to a record (Classic only), Google Drive public folder, Google Drive main folder, or a web source.

  1. Create a Custom Field
  2. Choose the URL Source
  3. Paste URL into the Custom Field
  4. Merge the Field into the Template

Create a Custom Field

  • Choose your base object, then create a custom field to hold the URL. Field type should be “long text” rather than URL, since the URL Sources in this article will have URLs that exceed the 255 character limit.
  • For example, if you’d like to merge a logo into a document and your base object is Opportunity, create a custom field (“Long Text” type) called Logo Link on the Opportunity object that displays the value of the Logo Link field.
  • Add this field to the object’s page layout.

Choose your URL Source

Choose from three supported sources for your publicly available URL:

Document attached to a record (Classic only)

In order to merge images into a document from a Documents file in Salesforce, you ‘ll need a publicly available URL to the direct image.

  • Go to Documents tab in Salesforce.
  • Select the checkbox “Externally Available Image” to make the document available externally.
  • Right click the image and select “Copy Image Address”.

File attached to a record (Lightning)

Files can now be shared publicly, so if you can save the public URL for the file into a custom “long text” type field, then you can use that field to merge onto a template. If you go to the file and click on File Sharing Settings, share with link, copy that link. Open it. Then, in order to get the URL of the image itself, right click on the image displayed and select “Copy Image Address” and proceed to the next step.

Google Drive – Public Folder

If you would like to merge images that are stored on Google Drive, this is possible; however, the link provided by Google does not work as provided so some modification is necessary.

  • Put your files in a public folder:
    • Create a folder or choose an existing folder.
    • Right click “Share” button at top right of screen.
    • Change settings to “Anyone with Link”=”Viewer”.

  • Any file in the folder will be made publicly available by entering URL in this format:<folderID>/<filename>.
  • For example, if you created a test folder on Google Drive and uploaded a file Test-Image.png, the Image URL is:
  • Copy the new image URL and proceed to next step.

Google Drive – Main Folder

If you don’t want to put files into a shared folder, you can use images that are uploaded directly to Google Drive (as long as they’re publicly accessible).

  • The image URL format will be:<file-ID>.
  • For example: If you uploaded a file directly to your drive with a file ID of 0BwdB0jiqM9yCM01iekxpdlc4ZHc, the Image URL is:
  • Copy the new image URL and proceed to the next step.

Web Source

You can merge images from a publicly available web source, such as your server, WordPress Media library etc.

  • To copy the direct URL of the image, right click the image and select “Copy Image Address” and proceed to the next step.

Paste URL into the Custom Field

  • Open the record and paste the copied image URL value into your custom “long text” type field.
  • For the example, we have an Opportunity record, Sustainable Energy Partnership, and would like to add a logo from a publicly available Documents file.
  • Paste the link into the Logo Link field on the Opportunity record.

Merge the Field into the Template

  • From your Document Action click “Edit Template Document” to edit the template.

  • Select the base object and image field. In this example, select “Opportunity” and select the image field, Opportunity>Logo Link
  • Check the “Image” checkbox.
  • The merge field code will populate in the “Merge Field Code” field at the bottom for you to copy and paste into the template body, header, or footer. 

Example Document Action Template:

Example Generated Quote Document:

Merge Related List Fields Into a Table


The configuration of your Document Action template can include merging related list fields from child object(s) down two levels. This allows configuration of your template to show related list fields of a child object, as well as related list fields of a child object’s child object.

  1. Build your Template
  2. Select your Base and Child Object(s)
  3. Apply Filters and Sorting
  4. Add your Related List Field(s) to the Table

Build your Template

  1. Create the Document Action and custom button following the Basic Configuration Getting Started article.
  2. Customize the Google Document. Add any text and images directly into the document that you want to be consistent elements within the template (Figure 1).
  3. Insert a table into the Google Document. Click Insert>Table. Select the number of rows and columns you want for your table (Figure 2).
  4. Format the table properties. You can edit the table border, color, dimensions, and other properties to suit your preferences. For example, if you don’t want your table to look like a table, you can make the border of your table invisible by changing the table border to “0 point” in Table Properties. To modify the table border, right click “Table Properties” within a table cell, then under “Table border” you can change the border point to “0”. You could also change the color of the border or modify width/table cell height (Figure 3).
  5. Add related lists. Click the Edit Template button on the top right corner of the Document Action screen. This will take you to Template Builder, where you can add Salesforce merge field code to your Google Docs template. The following sections cover the steps to add related lists to your table.

Figure 1

Figure 2

Figure 3

Select your Base and Child Object(s)

  1. Select your base object. When you select the base object, a menu of related lists will appear as well as a menu of all child objects with their related lists.
  2. Select the child object. Choose the child object and related lists to add to your template. For example, to create an Opportunity Summary that shows Opportunity Line Items, you would select Opportunity as the base object and Line Items as the child object. Related lists could include Opportunity Line Item Name, Quantity, List Price, and Total Price (Figure 1).
  3. Select the child object’s related object. If you would like to go down an additional level, select the child object’s related object from the menu that appears. Choose the related lists you wish to merge. For example, to create a Quote that shows Groups with Line Items, you would select Quote as the base object, Line Item Groups as the child object, and Line Items as the child object’s related object (Figure 2).

Note: If you want to merge a related list from an object that is not on the list of child objects, you would need to relate that object to the object being used as base object of the Document Action. 

Figure 1

Figure 2

Apply Filters and Sorting

  1. Select the related field you wish to merge from the list of related fields that appear when you select your child object or child object’s related object. If you do not wish to apply Filters or Sorting, continue to the next section.
  2. Apply Filters. You can set a Filter option for the entire table by adding it once to any of the fields you’re merging into the table. Specifically, you may want to filter on some of your related list items based on some condition or validation. For example, you may only want to merge Line Items from a specific group:
    1. Select the base object and child object, Quote and Line Item Groups.
    2. Select the child object’s related object, Line Items.
    3. Choose the related list, Product Name
    4. In the Apply Filter section, select the field you wish to filter by. In this case, select Group Name, then add your filter into the text box. In this case, if the filter is “Software”, only Line Items within the “Software” group will populate.
    5. The merge field code will appear in the Merge Field Code section (Figure 1).
  3. Apply Sorting. If you would like to sort your related list items in a certain order, you can use the Sort By feature. For example, you could sort by the Sort Order field, which is configured on the Opportunity record in Salesforce:
    1. Select the base and child objects, Opportunity and Opportunity Line Items.
    2. Choose the related list field, Opportunity Product Name.
    3. In the Sort By section, select Sort Order and A to Z for ascending order.
    4. Merge field code will populate in the Merge Field Code section (Figure 2).

Note: If you want to be able to sum up child records in Salesforce, you can use Rollup summary field for Master-Detail relationship Objects and can refer to this FAQ article for more detail.

Figure 1

Figure 2

Add Your Related List Field(s) to the Table

  1. Add the related list merge field code to one row of your table. Copy the merge field from the Merge Field Code text box and paste it into one row of the table you have created. The row will then repeat for each record (Figure 1, Figure 2). The related lists must be represented within a table so the rows can repeat with multiple values.
  2. Check the table layout. In order for the related list of the related list to populate, it must be added to a row directly below the merge code of the child object. If you add a row with text or otherwise separate the rows, the related list of the child object’s related object will not populate. Format the table such that the merge field code from the child object is in a row directly above the row containing merge field code from the child object’s related object (Figure 3, Figure 4).

Figure 1

Figure 2

Figure 3

Figure 4

Merge Fields into Google Docs Template

  1. After you saved your Document Action and created custom button following the Basic Configuration Getting Started article,  click “Edit Template Document” button in top right corner within document action to modify your Google Docs template with Salesforce merge data.
  2. Select parent Object and Field that you want to merge onto the document:
    1. If you need to select any field from related record of the object that is set in a lookup field, in the “Select Field” area all lookup fields will have “ID>” following the name. Click on it and a menu with fields from that object will show up on the right.
      For Example: If you need to access Account Name from Opportunity you should click Account ID > and then select Account Name from the menu that will show up.
  3. Copy the value from “Merge Field Code” and paste into the template.
    1. You can also include merge field in the document name (top left of document) so it merges a unique filename from each object record it is generated from.
    2. You can also merge fields (including images) into the “Header” and “Footer” of document just as you can merge into main body of document. From menu bar at top of Google Doc, click on “Insert” and then click on the header and/or footer to insert into document into document if not already visible. If you do merge a field in this area, the field value or image will show on every page of document.
  4. NOTE: If you are trying to merge Rich Text fields into template, please review this article.
  5. If you are ready to merge related list / child object items onto your template, move to the next article that shows you to merge these related list fields into a table.

Authorize One Google Drive Org Wide

This optional feature allows you to have one Salesforce user (eg admin) authorize the app under DocGen Configuration tab with a google drive that all other app users can generate documents to without having to do individual authorizations following this getting started article. All other users can then use this User’s permissions (User 1) to app components and all documents will be generated to same google drive that User 1 authorized.

  1. Go to your Salesforce Setup > Developer > Visualforce Page > Click on ‘Administration’ page.
  2. Click on “Preview” custom button on top right.
  3. From there, VisualForce page will come up and there will be a separate tab option on left for Drive authorization.
  4. Click on “Authorization” tab. The authorization section contains:
    1. Enable Authorization for all A5 Documents Users: One checkbox to define that Salesforce user can authorize on behalf of all other users.
    2. Authorization User: Picklist with a list of users to choose from in Salesforce to authorize drive for all other users (usually a system Admin).
    3. Force Authorization for all A5 Documents Users: Second checkbox to force this authorization for all users (do not check this optional box if you have any individual users that want to authorize their own google drive).
  5. Click to save settings
  6. After above steps done, go to A5 Documents Configuration tab to authorize and connect the Google Drive you would like to use for ALL your Salesforce users.
  7. After above steps are complete, test successful document generation under same Admin user.
  8. After document is generated successfully under Admin user, you can test this org wide feature by logging in as a different user (different than the user that you configured under Administration page) and test to generate document. This user should be able to also successfully generate document with no authorization error and the generated document will go to the same Google Drive as the Admin user specified.

If you need to revoke access and/or delete previous authorizations: 

  1. If you checked the box to ‘force authorization for all users,’ under Administration Visualforce page as outlined above, then this will override the previous authorizations.
  2. If you did not check this box or do not want to force authorization for ALL users, then you have option to individually revoke the google drive authorization token under each user:
    1. For each user that you want to revoke access, have their user go to A5 Documents Configuration tab and then click ‘Revoke Access’ red button shown below. Once they do this step, they will now generate documents to the same drive as the admin user specified as long as they had checked box  to define that ‘one user can authorize on behalf of all other users’ under Administration VisualForce page.
      1. If you need help with deleting previous app/google drive authorizations or having any issues setting up this feature, you can grant access to A5 Apps support in your org and submit a case to support for assistance.
    2. If this user or any other user still wants to authorize a separate google drive from the one admin specified, they can go back to A5 Document Configuration tab to click “grant access” and this will override the admin setting/drive (as long as the box was not checked under admin to ‘force this authorization for all users’).



Update Method of Payment

To Update Method of Payment (MOP) for A5 Documents:

  1. Have admin user (or user login linked with app subscription with proper permissions to make changes to app subscription) login to AppExchange and click your name in the top right, then ‘My Account’ or ‘My Installs & Subscriptions.”
  2. Click on the drop down arrow for A5 Documents subscription and click “manage subscription.”
  3. Click to edit and follow steps to update method of payment (use a credit card or ACH for direct bank account transfer)
  4. Click save.