When you leverage the S-Docs Batch document feature, you have the power to generate a large number of documents for any object with just a few clicks. Once you enable this feature, all you have to do is select an object, select the records that you would like to generate documents for, and select the S-Docs templates for each document generated. For example, if you need to generate an account summary for every account in your Salesforce database, S-Docs can provide you with a solution in just a few simple clicks.

Additionally, the mass merge feature provides the ability to merge an entire batch of documents into a single document in a matter of seconds. As an example, if your task was to generate and print a large number of documents, you could simply perform a mass merge and print the resulting document, rather than generate a document for each record, having to download and print each one individually. When you take advantage of the S-Docs mass merge and batch documents feature, you eliminate tedious work and gain more time to focus on the bigger picture.

Preview: The Mass Merge & Batch Document Feature in Action

Before we get into the details of setting up and configuring a mass merge, we will explore this feature in action. In the following preview, we will be generating account summaries for contacts and combining the resulting batch of documents into a single printable PDF. We begin by creating a list view that lists all of our contacts with overdue accounts, and selecting all of the resulting contacts.

mass merge - preview (1)

We then click the Add to Mass Merge List button at the top of the list view page to add these records to our mass merge list. We then click the View Mass Merge List button, bringing us to the mass merge page.

mass merge - preview (2)

We can set up our mass merge list to display important info about each record in our list. In this example, we have the mailing information for each of our contacts displayed in our mass merge list.

mass merge - preview (3)

We can then select up to 2 templates for batch document generation (note that the COMBINE ALL into single printable doc button only supports the selection of one template). In this case, we select the "Account Past Due” template. After selecting our template, we click Start Mass Merge and the templates are used to generate a unique document for each of the contacts in our mass merge list.

Note that there is a PDF icon next to each contact after generating the documents. A document can be downloaded by clicking on one of these icons. Each document is attached to the record it was generated for; if we go to the contact record page for “Anton Landers,” the documents will be included in the S-Docs related list on that page, where we can download and/or email each document whenever we’d like. Thus, we have generated a batch of documents for a group of contacts.

At this point, we click the COMBINE ALL into single printable doc button in order to combine all of the generated documents into a single PDF file. Note that this should only be done for printing documents generated by a single template.

We can also print mailing labels for each of our contacts. Click here for a free mailing label template. In the "Print Labels/Envelopes" tab, all S-Docs Templates with a Document Category of "Mailing Label" will be available to choose from (if your version of S-Docs is missing "Mailing Label" from the "Document Category" picklist on the S-Docs Template object, you'll need to add it to the picklist values manually). To do this, we simply select a label template and click Print Labels to download a single DOC containing all of the mailing labels for easy printing.

Please note that combining all of the documents in a single printable document is limited to PDF templates only; however, we can generate large numbers of documents for any output file format supported by S-Docs.

Once we download our mass merged PDF and mailing label, we print them and that’s it! We have just printed cover letters, account summaries, and mailing labels for ten contacts with overdue accounts in just a few clicks, and we can now mail these documents to the contacts in question.

In the remainder of this guide, we will be setting up the buttons, pages, and lists that will enable the mass merge and batch document features for a particular Salesforce object.

Note: You will need to have at least one template created for the object that you would like to use in your mass merge. Additionally, if you are following these steps for a contact, then you can skip to Step 4: Add Buttons to Search Layouts. This is because for contacts, the Visualforce page and the Add to Mass Merge List and View Mass Merge List buttons come prepackaged with S-Docs.

STEP 1: Setting up S-Docs Mass Merge

Setting up mass merge in S-Docs requires a Visualforce page (one for each object used in mass merge) and a single Apex class, which we've provided here.

Note that you'll only have to create the page SDMassMerge once for all the objects you are setting up mass merge on. However, you will need to set up the Apex class and other Visualforce pages for each object you are setting up mass merge on.

Create a new Apex class (Setup > Build > Develop > Apex Classes > New) using the following code (you only need to create this class once):

Your Apex Class should look like this:


For each object that users will perform mass merge on, you'll need to create a Visualforce page (Setup > Build > Develop > Visualforce Pages > New) called SDAddToMassMergeCHANGE_TO_YOUR_OBJECT_NAME using the following code: (Note: Make sure to change OBJECTAPINAME in the first line of code to the name of your object.)

Note: When naming your Visualforce page, omit the __c if your object name contains it, as double underscores aren't allowed in VisualForce page names (but the __c does need to be included for custom objects in the code for the VisualForce page). It actually doesn't matter what the name of your page is. SDAddToMassMergeCHANGE_TO_YOUR_OBJECT_NAME is simply a naming convention intended to keep your Visualforce page collection neat and organized in case you have to create this page for several objects.

Make sure Available for Lightning Experience... is checked. For example, if your object API name is Opportunity, your Visualforce Page should look like this:


If you require test coverage for the SDAddToMassMerge class, you can use the following test class:

To recap, you'll need to create a page for each object (and later a button for each object), though you'll only need to create the Apex class once. For example, after you performed these steps for 3 different objects, you would have created 3 Visualforce pages (one for each object), but just one Apex class (this class would control all 3 pages).

 

STEP 2: Create the "Add To Mass Merge List" button

1. Now, navigate to the “Buttons, Links, and Actions” page for the Salesforce object that you would like to use in a mass merge.

If you’re performing a mass merge on a custom object, please follow the instructions for part (a) and skip the instructions in part (b). If you’re performing a mass merge on a standard object, please skip the instructions in part (a) and follow the instructions in part (b).

a.) Creating a new button for a custom object.

Navigate to Setup > Build > Create > Objects.

mass merge - step 1 (1)

Find the name of the custom object that you would like to use in a mass merge and click the name of this object (do not click the edit button). In this example, we will be creating an Add to Mass Merge List button for the Check object, a custom object representing the data for a standard business check.

mass merge - step 1 (2)

Next, a page will display for your custom object. Please take note of the API name at this point, as you will require it in later steps. The API name is often just the “Object Name” appended with __c (note the two underscores), but sometimes this is not the case, so please take note of that here. In the case of our custom Check object, we will note that our API name is Check__c.

mass merge - step 1 (3)

On the page for your custom object, scroll down to “Buttons, Links, and Actions” and click New Button or Link.

mass merge - step 1 (4)

This concludes part (a).

b.) Creating a new button for a standard object.

Navigate to Setup > Build > Customize > YourObjectNameHere > Buttons, Links, and Actions.

mass merge - step 1 (5)

Once you’re on the “Buttons, Links, and Actions” page for your standard object, click New Button or Link.

mass merge - step 1 (6)

At this point, please note the API name for your standard object:

mass merge - step 1 (7)

Note that the API name is the same as the object name for all objects except for products; for a product, the API name will be Product2.

This concludes part (b).

2. We will now define our button. For the fields listed on the “New Button or Link” page, please use the following:

Label: Add to Mass Merge List
Name: Add_to_Mass_Merge_List
Display type: List Button (please ensure that Display Checkboxes (for Multi-Record Selection) is checked as well)
Behavior: Display in Existing Window without Sidebar or Header
Content Source: URL
URL: /apex/SDAddToMassMergeCHANGE_TO_YOUR_OBJECT_NAME?objectName=CHANGE_TO_YOUR_OBJECT_API_NAME

Once completed, the page should appear as follows:

Note: If your use case requires a View Mass Merge List button in addition to the Add To Mass Merge List button, you can simply repeat this step, naming the button "View Mass Merge List" instead of "Add To Mass Merge." This works because the Add To Mass Merge button redirects to the mass merge page by default.

STEP 3: Add Button to Search Layout

1. You will now need to edit the list view page for your object.

If you’re performing a mass merge on a custom object, please follow the instructions for part (a) and skip the instructions in part (b). If you’re performing a mass merge on a standard object, please skip the instructions in part (a) and follow the instructions in part (b).

a.) Adding buttons to search layouts for a custom object.

Navigate to Setup > Build > Create > Objects.

mass merge - step 4 (1)

Find the name of the custom object that you would like to use in a mass merge and click the name of this object (do not click the Edit button). In this example, we will be adding buttons to a custom Check object’s layout page.

mass merge - step 4 (2)

Now, scroll down to the Search Layouts table. Click Edit next to the layout titled “[Object Name] List View,” where [Object Name] is the name of your object (excluding brackets).

mass merge - step 4 (3)

This concludes part (a).

b) Adding buttons to search layouts for a standard object.

Navigate to Setup > Build > Customize > YourObjectNameHere > Search Layouts.

mass merge - step 4 (4)

2. Now that you’re on the Edit List View page for your Object, select Add to Mass Merge List under “Available Buttons” and click the rightward-pointing arrow below Add to add your button to “Selected Buttons.” Repeat this step for “View Mass Merge List” if you created a button for it. Click Save.

The finished page should appear as:

 

This concludes part (b).

STEP 4 (Optional): Create a List View for Your Object

If you wish to use list views that have already been created for your object, such as the ‘All’ list view, you may skip this step. However, for the list view you select, you will have to manually filter out all the documents you would not like to appear in your mass merge. This might be tedious, and if you have some kind of criteria that would greatly optimize this process (e.g. you wish to print all Checks written for amounts less than $10,000), you can follow the instructions in this step to create a list view and use filter logic to achieve such goals.

1. Navigate to the tab for your object. In this example, we will be navigating to the tab for our Check object; it happens to be displayed as a default tab, but if it weren’t displayed, we could click the “All Tabs” tab ("+" symbol) and find it from there:

mass merge - step 5 (1)

For the mass merge and batch document feature, we are usually dealing with a large number of records. For this reason, it would typically be to our benefit to automatically filter out some or all of the records that we do not wish to generate before proceeding to the actual mass merge. To begin doing this, click Create New View on our Object’s page:

mass merge - step 5 (2)

Enter a descriptive View Name (after doing this, View Unique Name should fill in automatically). For “Filter by Additional Fields,” you can select filter logic to filter certain records in our List View. In this example, we selected “Dollar Amount (Num)” for a Field to filter by, “less than” for the logic Operator, and “10000” for the Value. This means that our list will only include Checks written for amounts of less than $10,000.

mass merge - step 5 (3)

In “Select Fields to Display,” the name of each record is a Selected Field by default. We can add additional fields to assist in manual filtering later on. To do this, click the name of the field you would like to add, and then click the arrow below Add to add the field from “Available Fields” to “Selected Fields.” In this example, we added “Pay To Order Of” and “Dollar Amount (Num)” to the Selected Fields (in addition to Check Name which is there by default). Finally, select an appropriate option for “Restrict Visibility” and then click Save. You will be redirected to the resulting List View. In our Check Example, our list does not contain checks 2 or 5 as their “Dollar Amount (Num)” fields are greater than or equal to $10,000. Click the checkbox next to Action if you would like to select all the records to be added to the mass merge. You can also select or deselect them individually.

mass merge - step 5 (4)

Note that we have our “Pay To Order Of” and “Dollar Amount (Num)” fields displayed in case we want to manually exclude a certain Payee’s check or a check of a certain dollar amount from our mass merge list. If we didn’t want to include one of these checks in our mass merge, we uncheck it. In this example, suppose that after filtering out checks with values greater than or equal to $10,000, we decided not to include the check paid to the order of Douglas L. Smith. Since we included the “Pay To Order Of” field as a column, we don’t have to open all three records to see which one will be paid to Douglas L. Smith; we can simply eyeball the list and uncheck the record corresponding to him. Then, this check will not appear in the resulting mass merge.

Note: We discussed a similar method in Step 2. Users can manually exclude records from their mass merge based on the fields displayed in the search layout list view as described above, or based on the fields displayed in the mass merge list described in Step 2. The latter technique is achieved by following the instructions for editing the Visualforce code in Step 2; the technique in Step 5 might be simpler to achieve.

mass merge - step 5 (5)

STEP 5: Use the Mass Merge & Batch Document Feature

Before we use the mass merge and batch document feature, we need to make sure that the list of S-Docs Jobs logs is clear. S-Docs Job records are created when we add records to a mass merge list; they are not deleted after you finish the mass merge. They may also be created if someone in your org has created APEX triggers, Salesforce flows, workflows, etc. that automatically generate Job records upon certain events. Thus, even if you are setting up a mass merge for the first time, there still might be S-Docs Job records that you will have to clear. So, let’s see how we can clean up the S-Docs Jobs log list.

Click All Tabs ("+" symbol), then click S-Docs Jobs.

mass merge - step 6 (1)

Click Go! next to the list view for “All (Installed Package: SDocs).” Note that the “Recent S-Docs Jobs” list might be empty even when we have a large number of S-Docs Job records because this list only displays recently viewed records.

mass merge - step 6 (2)

Click the top checkbox next to Action to select all the records, then click the Delete Logs button to delete all the S-Docs Job records.

mass merge - step 6 (3)

Now we can perform our mass merge. Navigate to the page for your object and select a list view. In our Check example, we selected the list view “Checks Less Than $10,000” that we created in Step 5. Select the records that you would like to use for the mass merge and batch document feature. Then, click Add to Mass Merge List. Finally, click View Mass Merge List.

mass merge - step 6 (4)

Select the template(s) that you would like to use for document generation.

mass merge - step 6 (5)

Click Start Mass Merge and wait for the Status Link to be 100% for all documents (the Status Link is the progress of generation for a given individual document; 100% means that document has been generated, and you can click the icon next to the 100% to open that particular document). Once the Status Link is at 100% for all documents, click COMBINE ALL into single printable doc (note that this button is limited to one template only; you should use this button if you generated documents for 2 or more templates). The mass merged document will download to your computer, thus completing the process.

mass merge - step 6 (6)

In our check example, we will open the PDF that downloaded after clicking COMBINE ALL into single printable doc. As expected, the PDF contains both of our checks, each on its own page.

mass merge - step 6 (7)

Generating and Emailing a Large Number of Documents

If you would like to generate and email a large number of documents, you can do so by selecting two templates in our mass merge: one template for the document you’d like to email, and another template for the email itself. Thus, to generate and email a large number of documents, all you have to do is select an S-Doc HTML email template and an S-Doc template for a PDF, Word document, etc. on our mass merge page, and then click Start Mass Merge. That’s it! S-Docs will then use the information in the HTML email template to send a personalized email to each record in our mass merge list; each of these emails will include the document that was generated for that particular record.

mass merge - emails (1)

Generating and Printing Mailing Labels for your Mass Merge

If you plan on performing a mass merge, printing the resulting PDF, and mailing out the pages, you can use S-Docs to print off mailing labels for your letters. To do so, you first have to create a new S-Docs template for your mailing label (click here for a free mailing label template). Please make sure your template has the "Document Category" field set to "Mailing Label" (if your version of S-Docs is missing "Mailing Label" from the "Document Category" picklist on the S-Docs Template object, you'll need to add it to the picklist values manually), and that your mailing label template has User as its "Related To Type" and DOC or PDF as its output type; this is because S-Docs populates the mailing label list on the mass merge page with all S-Docs templates that meet these criteria.

You can copy and paste the following mailing label template into your label template’s source editor:

This template will print mailing labels for a list of contacts.

On the mass merge list page, you can then select your mailing label from the “Label Template” list.

mass merge - mailing (1)

You can then click Print Labels to generate and download a printable mailing label.

mass merge - mailing (2)

Appendix

Finding the API names for Your Standard Object’s Fields

Navigate to Setup > Build > Customize > YourObjectNameHere > Fields.

mass merge - appendix (1)

For standard field names, the API names are found under the “Field Name” column. For Custom Fields, the API names are found under the “API name” column.

mass merge - appendix (2)

Finding the API names for Your Custom Object’s Fields

Navigate to Setup > Build > Create > Objects.

mass merge - appendix (3)

Find the name of the object for which you require Field API names, and click the name of the object (do not click the Edit button). In this example, we will be finding the API names of Fields for a Check, a Custom Object representing the data for a standard business check.

mass merge - appendix (4)

On the page for your Custom Object, scroll down to the “Standard Fields” and “Custom Fields & Relationships.”

The API names for Standard Fields will be located under the “Field Name” column, and the API names for Custom Fields will be located under the “API name" column.

mass merge - appendix (5)