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.
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.
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.
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.
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.
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. To get this page, navigate to Setup > Build > Develop > Apex Classes > New.
Paste in the following code (you only need to create this class once):
Your Apex Class should look like this:
Click Save. Next, for each object that users will perform mass merge on, you'll need to create a Visualforce page. Navigate to Setup > Build > Develop > Visualforce Pages > New.
Create a new Visualforce page called SDAddToMassMergeCHANGE_TO_YOUR_OBJECT_NAME using the following code:
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.
Note: If you’re performing a mass merge on a custom object, please follow the instructions for part (a). If you’re performing a mass merge on a standard object, please follow the instructions in part (b).
a.) Creating a new button for a custom object.
Navigate to Setup > Build > Create > Objects.
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.
Next, a page will display for your custom object.
On the page for your custom object, scroll down to “Buttons, Links, and Actions” and click New Button or Link.
This concludes part (a).
b.) Creating a new button for a standard object.
Navigate to Setup > Build > Customize > YourObjectNameHere > Buttons, Links, and Actions.
Once you’re on the “Buttons, Links, and Actions” page for your standard object, click New Button or Link.
At this point, please note the API name for your standard object:
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
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
Once completed, the page should appear as follows:
STEP 3: Add Button to Search Layout
1. You will now need to edit the list view page for your object.
a.) Adding buttons to search layouts for a custom object.
Navigate to Setup > Build > Create > Objects.
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.
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).
This concludes part (a).
b) Adding buttons to search layouts for a standard object.
Navigate to Setup > Build > Customize > YourObjectNameHere > Search Layouts.
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).
Winter '20 Release Note: If you are using S-Docs below version 4.53, you may experience an "Attempt to de-reference a null object" error when interacting with various forms of automation in S-Docs. In order to fix this bug, you can create a new SDocs Settings custom settings set. To do this, type "Custom Settings" into the Quick Find / Search bar in the Setup menu, and click Custom Settings. Click SDocsSettings, then click Manage at the top of the page. From there, click New. Fill out the following information:
SD Jobs Batch Size: 30
SD Jobs Move to Top of Flex Queue: ☑
Additionally, ensure that you have a Remote Site Setting for either login.salesforce.com (production), or test.salesforce.com (sandbox).
STEP 4 (Optional): Create a List View for Your Object
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 button ("+" symbol) and find it from there:
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:
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.
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.
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.
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.
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.
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.
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.
Select the template(s) that you would like to use for document generation.
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.
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.
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.
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.
You can then click Print Labels to generate and download a printable mailing label.
Finding the API names for Your Standard Object’s Fields
Navigate to Setup > Build > Customize > YourObjectNameHere > Fields.
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.
Finding the API names for Your Custom Object’s Fields
Navigate to Setup > Build > Create > Objects.
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.
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.