Category

Documentation

Use S-Docs with your custom object

By Documentation, General Solutions, S-Docs Cookbook No Comments

S-Docs works great with your custom objects, but there are a few configuration steps you will need to take.

Below, you will find an overview of the configuration steps. Detailed step-by-step instructions on how to configure S-Docs with your custom object are available here: Configuring S-Docs with Custom Objects.

First, you will need to add your custom object to the picklist value “Related to Type” field in the SDOC Template object. When adding your object, be sure to use your object’s API name (e.g. myObject__c) as the new picklist value. This step is critical, as it allows S-Docs templates to be associated to your custom object.

Second, you need to create an S-Docs button and place it on your custom object’s detail page. We’ve found that a Detail Page button displayed in the “existing window without sidebar or header” works great.

You should create a button link using a URL similar to the following, but replacing ‘myObject__c’ with your Custom Object API name:

{!URLFOR('/apex/SDOC__SDCreate1', null,[id=myObject__c.Id, Object='myObject__c'])}

Lastly, this step allows generated S-Docs to be associated to your custom object and further allows you to place an S-Docs related list on your custom object’s detail page layout. You simply need to add a look-up field to the SDOC Relationship object that points to your custom object.

Note: The “Field Name” of this new lookup field must match the name of your object (e.g. myObject) without the “__c.”

Discussion: When using S-Docs with custom objects, the field template designer will automatically correct and append your related object fields with a “__r.” If you are comfortable creating your templates in the source code, be sure to use the standard Salesforce conventions and dot notation and be mindful of capitalization differences.

Automating Conditional Template Selection and Generation

By Documentation, S-Docs One-Click and Zero-Click No Comments

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:

Name: SDocsSettings
ConnectedAppLoginURL:
Production: login.salesforce.com
Sandbox: test.salesforce.com
SD Jobs Batch Size: 45
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).

Note: This guide builds on automation features discussed in the one-click and zero-click guide (Automation Options Improving Efficiency and Compliance).

Introduction

With the use of Salesforce logic in the S-Docs button URL, you have an endless amount of possibilities for automating template selection and generation. You can easily modify the standard S-Docs button code so that when users click the button, S-Docs will automatically select or generate certain documents depending on the values in a record’s fields.

For example, suppose that we have multiple templates for a letter sent to contacts, and that this letter will vary depending on what a given contact’s department is. If the variation is small, we could handle this using render statements. But suppose these were completely different letters requiring completely different templates, and we don’t want to require our sales team to memorize the contact’s department, click the S-Docs button on the contact record’s page, and then have to click the appropriate letter template prior to document generation. We’d rather have a user in our org just click S-Docs and be immediately taken to their templates.

We can accomplish this by editing an object’s existing S-Docs button, or creating a new button if you’d like users to have the option of using the normal S-Docs button in case they need to manually select templates. In this case, we’ll go with the first choice, and simply edit our existing S-Docs button.

Using The Doclist Parameter

In the following sections, we will be automatically selecting documents with the doclist Apex parameter. To use this, we simply append the following to our S-Docs button code:

doclist='YourTemplateNameHere1,YourTemplateNameHere2,YourTemplateNameHere3…'

Note: If you have multiple templates with the same name, they will all generate if one of them is referenced by this parameter.

You can also use template IDs for the doclist parameter, however this is not recommended because these IDs will change between sandbox and production orgs, meaning that you will have to re-add the new template IDs into this parameter after transferring to production.

The doclist can include as many S-Doc templates as you’d like. If you just append the doclist parameter, templates will be automatically selected and generated. If you would like your S-Docs templates to be automatically selected, but not automatically generated, you can append oneclick='false' to your S-Docs button code as well, as this parameter modulates the doclist parameter. For a full list of button parameters, please visit our Apex Parameter documentation.

Two Outcomes: True or False (IF Function)

Let’s suppose that members of every department except finance gets letters derived from the same template, and the finance department gets letters derived from a different, special template. This means that we have two outcomes to consider in our automatic template selection: the contact is in the finance department, or the contact is in some other department. So, we handle this with the doclist Apex parameter and an IF function that determines the templates to be included in the doclist. The button URL would look like this:

[code lang="html"]{!URLFOR('/apex/SDOC__SDCreate1', null,[id=Contact.Id, Object='Contact',
doclist=IF(Contact.department=='Finance', 'Finance_Letter', 'All_Depts_Letter')])}[/code]

We see that if the contact’s department is “Finance,” then the template will be "Finance_Letter," which happens to be the S-Docs template for our special finance department letter. However, if the contact’s department is not “Finance,” then the doclist parameter will be "All_Depts_Letter," which is the template for our letter for all other departments.

More Than Two Outcomes (CASE Function)

Now suppose that members of technology departments will also receive a totally different letter. This means we can’t use an IF function, as we now have three outcomes; the contact could be in the finance department, the technology department, or in some other department. This means we’ll have to use the CASE function instead. The button URL would look like this:

[code lang="html"]{!URLFOR('/apex/SDOC__SDCreate1', null,[id=Contact.Id, Object='Contact',
doclist=CASE(Contact.department, 'Finance', 'Finance_Letter', 'Technology', 'Technology_Letter', 'All_Depts_Letter')])}[/code]

We see that the finance department will get their own letter, the technology department their own letter, and since else_result is “All_Depts_Letter," all other departments will receive letters derived from the same template.

Building a Doclist with Multiple Functions

Now, suppose that we’d like to send an account’s primary contact a questionnaire regarding how much they like our product. Additionally, suppose we have two true/false fields: Up_For_Renewal__c and Receives_Discount__c, which respectively denote whether the account is up for renewal and whether the account is eligible for a discount. We’re sending the account’s primary contact the questionnaire no matter what, and depending on the status of the other two fields, we may or may not send a letter informing them that they are up for renewal, and possibly some kind of coupon code or voucher if they are eligible for a discount. Let’s say the questionnaire template is named "Questionnaire_Template," the up-for-renewal template is named "Renewal_Letter," and the coupon code template is named "Coupon_Code."

Then, we could accomplish this with the following button URL:

[code lang="html"]{!URLFOR('/apex/SDOC__SDCreate1', null,
[
id=Account.Id,
Object='Account',
doclist='Questionnaire_Template' +
IF(Account.Up_For_Renewal__c, ',Renewal_Letter', "") +
IF(Account.Receives_Discount__c, ',Coupon_Code', "")
]
)}[/code]

Since we’re sending the questionnaire no matter what, its template name is at the front of the doclist outside of the IF function. Then, we have two IF functions that will return a template (each of which is preceded by a comma, since our doclist must be comma-delimited without spaces) if their respective fields are true. So, if Up_For_Renewal__c and Receives_Discount__c are both true, our resulting doclist will be:
Questionnaire_Template,Renewal_Letter,Coupon_Code.

If  Up_For_Renewal__c is false and Receives_Discount__c is true, our resulting doclist will be:
Questionnaire_Template,Coupon_Code.

If both of these fields are false, our resulting doclist will be:
Questionnaire_Template.

In the last case, this is because value_if_false for our two IF functions is an empty string (specified as two quotation marks with nothing between them). Don’t worry about the additional commas; S-Docs will ignore these and just generate the document with the template name Questionnaire_Template. We could place commas inside of our code’s quotation marks such that they would always yield clean-looking doclists. However, this might take a bit more thought and work to write, and could be more prone to mistakes (or you might think the opposite; it’s a matter of personal preference). No one’s really looking at the resulting doclist after your IF functions evaluate; it’s just used internally by S-Docs to find which templates to use. So, you don’t need to worry about what your doclist evaluates either, as long as the logic is correct and there is at least one comma between each template name whenever the doclist evaluates.

Nested IF Functions

Our code’s structure in the previous example is very useful in plenty of cases. However, it might not make sense to send an account a coupon code along with the questionnaire if they aren’t up for renewal. We might want to send that coupon code only if they’re up for renewal. We can accomplish this using a nested IF function:

[code lang="html"]{!URLFOR('/apex/SDOC__SDCreate1', null,
[
id=Account.Id,
Object='Account',
doclist='Questionnaire_Template' +
IF(Account.Up_For_Renewal__c, ',Renewal_Letter' +
IF(Account.Receives_Discount__c, ',Coupon_Code', ""), "")
]
)}[/code]

Let’s take this statement apart. Our questionnaire’s template name, Questionnaire_Template, will be on our doclist no matter what. Now, what happens if Account.Up_For_Renewal__c is true? First, note that we included a comma at the end Renewal_Letter; this comma is inside the string, since we don’t want to confuse our IF function with extra commas laying outside the string. We then followed this string with an ampersand (i.e. the concatenation operator) and a nested IF function. Whatever the nested IF function returns will be concatenated to the end of the following string: Renewal_Letter.

So, if Account.Up_For_Renewal__c is true, and Account.Receives_Discount__c is false, our resulting doclist will be:
Questionnaire_Template,Renewal_Letter.

Then, if Account.Up_For_Renewal__c and Account.Receives_Discount__c are both true, our resulting doclist will be:
Questionnaire_Template,Renewal_Letter,Coupon_Code.

And finally, if Account.Up_For_Renewal__c is false and Account.Receives_Discount__c is true, our resulting doclist will be:
Questionnaire_Template.

In other words, accounts will receive just the questionnaire if they aren’t up for renewal, even if they are eligible for the discount. No need to jump the gun on that coupon code!

Using AND/OR Functions

AND/OR functions can be used with the doclist parameter as well. For example, say we become big fans of small business and decide to create a promotional period in which accounts with annual revenues less than $100,000 will also receive a coupon code, even if Account.Receives_Discount__c is false. To accomplish this, we can place an OR function inside of our IF function:

[code lang="html"]{!URLFOR('/apex/SDOC__SDCreate1', null,
[
id=Account.Id,
Object='Account',
doclist='Questionnaire_Template' +
IF(Account.Up_For_Renewal__c, ',Renewal_Letter' +
IF( OR(Account.Receives_Discount__c, Account.AnnualRevenue < 100000),',Coupon_Code', ""), "")
]
)}[/code]

Automation Options: Improving Efficiency and Compliance

By Documentation, S-Docs One-Click and Zero-Click No Comments

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:

Name: SDocsSettings
ConnectedAppLoginURL:
Production: login.salesforce.com
Sandbox: test.salesforce.com
SD Jobs Batch Size: 45
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).

FEATURE OVERVIEW

S-Docs is a powerful tool that allows you to generate and email documents natively on the Salesforce platform. By default, the user experience is very flexible. However, this flexibility means that the user makes all decisions during the document generation and distribution process, which takes time. As an administrator, you may want to automate the process to gain efficiency (to reduce time and clicks), reduce errors (by pre-selecting correct templates based on data) and to ensure compliance (to enforce business rules). S-Docs provides a one-click and zero-click feature described in this document to ensure you can tailor the user experience to meet your business requirements.

The document automation process can be considered a spectrum from maximum flexibility to maximum automation. The out-of-box behavior of S-Docs provides maximum user flexibility. In this use case, the user chooses the document(s), along with the default email template. They decide whether to include additional attachments, determine email recipients, and then finally decide if they want to print or email the generated document(s).

With S-Docs, you can achieve complete automation – meaning an event or field change could drive a fully automated document generation and distribution process, even when the user is not logged into Salesforce! For example, an account status changed to “closed” could generate a win-back email and special offer without any user involvement. Or, a case status change to “Ready for Proposal” could generate a proposal and send it to the client. You can see that there is a huge opportunity to improve your business process. As an administrator, you determine what level of automation is appropriate for your organization to meet your requirements. This document explains how S-Docs can be used to achieve those results.

S-DOCS AUTOMATION SPECTRUM

Maximum Flexibility [Most clicks]                                                          Maximum Automation [Least clicks]
OPTION 1 OPTION 2 OPTION 3 OPTION 4 OPTION 5 OPTION 6
Default S-Docs Behavior Pre-select “One Click” One-Click + Email Prep One-Click + Email Send “Zero-Click”
User chooses every aspect of doc generation, attachments, and email options. You can add filter rules to help selection process. Saves one step to filtering by selecting the default document(s) based on data such as language or product type. User can override pre-selected  docs as needed. Documents along with email cover letter are generated with a single click. User can then choose to print, return to record or proceed to email. One-click leads to fully populated email page with all attachments, default email message and recipients completed. User can verify email and make edits as needed before sending. One-click, document(s) are generated and emailed. Screen returns to the record detail page without any further user input. User cannot change document or messaging. A Field change, or workflow sets off a trigger that generates and optionally emails the document(s). This is fully automated and ideal for mobile devices.

CONFIGURATIONS

The following options provide you with edits to the S-Docs button that you can use to increase automation. To get to the button edit page, navigate to the Setup menu and click Object Manager. Click the name of your object.

Then, navigate to the Buttons, Links, and Actions tab. Find the S-Docs button, click the arrow on the right, and click Edit.

Note: The S-Docs button comes prepackaged for the following standard objects: Contract, Opportunity, Account, Contact, Lead, Task, and Event. Because of this, the button will be managed and therefore unable to be edited for these objects. You will need to create a new S-Docs button (and replace the old button on the object's page layout) to make edits.

OPTION 1: Default Behavior & Adding Template Filters

S-Docs default behavior allows a user to choose any document(s) to generate along with any email template. The user can then decide to print or email the document. If emailed, the user can attach additional files, add recipients and customize the email message before it is sent. While this provides for maximum flexibility, it also requires the greatest amount of user interaction (clicks).

You can reduce template searching by optionally providing an initial search filter to the template list. When the user clicks on the S-Docs button, a subset of templates can be displayed to help them find the most likely one needed. This is done by using a search filter and/or category filter, as in the button URL. But keep in mind, the Salesforce user will still need to click the checkbox next to the template and then click the “Next" button to continue. If you want the box checked for them, you need to move to Option 2. Option 1 is useful when you have many templates and want to simply help the user by providing the likely choice. Users can still search for and use other templates as needed.

The first example below shows the button syntax where the templates are initially filtered based on a dynamic field value such as the language preference of the client. Using the “searchfilter” parameter below will automatically display only templates that have a “Name” or “Description” field that contains the value of the searchfilter parameter.

Button or Link URL:

[code lang="html"]{!URLFOR('/apex/SDOC__SDCreate1', null,[id=Opportunity.Id, Object='Opportunity',
searchfilter=Opportunity.ContactLanguage__c])}[/code]

Similarly, you can filter based on the value of the template’s “category” field. In this example, only templates with a category of “Contract” will be displayed by default. Button or Link URL:

[code lang="html"]{!URLFOR('/apex/SDOC__SDCreate1', null,[id=Opportunity.Id, Object='Opportunity',
categoryfilter='Contract'])}[/code]

Note:You can use both searchfilter and categoryfilter parameters together within the same button. When doing so, both conditions need to be met for the related templates to appear (i.e. they are joined by an “AND” condition).
Note 2:
If you want to restrict access to templates based on user or profile, you can easily implement this using Salesforce’s sharing model feature. You would need to change the SDTemplate object to a private sharing model and then configure your sharing rules based on your business requirements.

Option 2: Pre-select Templates:

This option will save users an additional click by automatically pre-selecting (filtering and checking off) the document to be generated. The user can still remove the pre-selected template and choose their own if they wish to override the default selection. The user will then need to click on the Next Step button to generate the document. This option is useful when you have business rules that can identify the correct template in the majority of use cases, but still allows the user to override the default selection if needed.

This automation is achieved by passing the template’s name into a URL parameter called “doclist.” This parameter can contain multiple template names, but they must be separated by a comma. Additionally, the oneclick parameter needs to be set to false. This tells the S-Docs engine to stop for further input. Note that if there are multiple templates with the same name in your org, all of them will generate if one of them is referenced by this parameter.

Note: You can also use template IDs for the doclist parameter, however this is not recommended because these IDs will change between sandbox and production orgs, meaning that you will have to re-add the new template IDs into this parameter after transferring to production.

S-Docs Button or link URL:

[code lang="html"]{!URLFOR('/apex/SDOC__SDCreate1', null,[id=Opportunity.Id, Object='Opportunity',
doclist='Template_1,Template_2',
oneclick='false'])}[/code]

The doclist parameter can also be dynamically set using Salesforce functions within the button like “IF” or “CASE.” This button will choose the correct document and email template based on a field value. S-Docs Button or link URL:

[code lang="html"]{!URLFOR('/apex/SDOC__SDCreate1', null,[id=Contact.Id, Object='Contact',
doclist=IF(Contact.Department=='Finance', 'Finance_Template', 'All_Other_Depts_Template')])}[/code]

Option 3: One-Click Generation

The “one-click” builds on Option 2 but takes it one step further – the document(s) are generated without the user selecting any templates. Once the user clicks the S-Docs button, they will go directly to the list of newly generated documents. From there, they can then decide to view, print, email or return to the original Salesforce record. This option achieves one-click generation while still allowing the user to determine next steps.

One-click configuration is a similar URL to option 2, but should NOT contain the “oneclick='false'” parameter. Only the doclist parameter (which contains a comma delimited list of documents) is needed.

S-Docs Button or link URL:

[code lang="html"]{!URLFOR('/apex/SDOC__SDCreate1', null,[id=Opportunity.Id, Object='Opportunity',
doclist='Template_1,Template_2'])}[/code]

Option 4: One-Click + Email Prep

The “one-click” builds on Option 3 but again goes one step further – by pushing the user and documents to an email screen. To effectively use this option, one of the templates in the doclist should be of type “HTML.” This HTML template will comprise the default email body and can set the default subject line and recipients for the outbound email being prepared.

Any other S-Docs templates that are included in the doclist will be automatically added as attachments. This option is appropriate where you want to give the user the opportunity to “eyeball” the email and make any small changes prior to sending. You can leverage the advanced features of the S-Docs Template to default all email values and lock down fields where you want to restrict the users. One-click is configured with a “prepemail='1'” parameter in the S-Docs button URL. Only the doclist parameter (which contains a comma delimited list of template names) and prepemail parameters are needed. Again, when using this feature, one of the templates in the doclist should have an output type of “HTML” that will set the default email body. S-Docs Button or link URL:

[code lang="html"]{!URLFOR('/apex/SDOC__SDCreate1', null,[id=Opportunity.Id, Object='Opportunity',
doclist='Email_Template,Template_1',
prepemail='1'])}[/code]

Option 5: One-Click + Email Send

This option will create the document and email it according to the parameters in the button and the configuration of the S-Docs templates included in the doclist parameter. This MUST contain an HTML template as one of the doclist parameters, and that template MUST contain at least a default “To” address, subject line and email body. Without this set, it will not be a valid email. The users will return to the original record detail page once complete. This is a useful option when you want complete control of the messaging but still allow the user to control when the message is generated.

S-Docs Button or link URL:

[code lang="html"]{!URLFOR('/apex/SDOC__SDCreate1', null,[id=Opportunity.Id, Object='Opportunity',
doclist='Email_Template,Template_1',
sendemail='1'])}[/code]

You can include additional email attachments to your outbound email by specifying the document ID or attachment ID parameters. Keep in mind that these records need to exist within Salesforce prior to the document generation process so their IDs can be included in the URL. Attachments use the parameter “aid=”  followed by a comma delimited list of Salesforce IDs corresponding to attachment records. Salesforce documents use the parameter “did=” and the list of Salesforce IDs for the document record. S-Docs Button or link URL with additional attachments from attachment related list and documents tab:

[code lang="html"]{!URLFOR('/apex/SDOC__SDCreate1', null,[id=Opportunity.Id, Object='Opportunity'
doclist='Email_Template,Template_1',
aid='00PG0000006neU1',
did='015G0000001gbu9,015G0000002qtXw',
sendemail='1'])}[/code]

Option 6: Zero Click

This option can create documents and emails from the Salesforce platform whenever a field is set to a particular value. You can therefore use workflow rules to update a field value, which in turn can generate and optionally email documents through S-Docs. This option is ideal for behind-the-scenes document generation and distribution. It is also ideal for mobile devices, since it is a field change that runs a process without further user interaction. For example, you can easily add a custom picklist field on a mobile page layout. The user simply changes the value and saves the record. All document processing is handled post-save on the Salesforce platform. You can also do this without even prompting the user through workflow rules!

This integration uses the S-Docs Jobs Object in conjunction with the Salesforce Process Builder, Visual Workflows, or APEX triggers. You can learn how to use S-Docs Jobs for zero-click automation by reading this documentation.

Conditional logic within a template

By Documentation No Comments

Feature Overview

S-Docs Render is a powerful feature that permits sections (or blocks) of text and data to display in your generated document only when a condition is met. This provides a mechanism to create a single template that can dynamically show and hide portions of the document based on conditional logic.

While you can also achieve simple dynamic rendering within your S-Docs templates by only using Salesforce formula fields (without the S-Docs Render feature), this approach has limitations and can be difficult to scale.

To address these limitations, S-Docs provides two levels of Rendering: Basic Render and Advanced Render.

The Basic Render feature can be used to show or hide a block of your S-Docs template based on a single condition. We suggest this approach first because it is simple and can meet most requirements.

For more complex requirements where advanced logic is needed, the S-Docs Advanced Render feature can be leveraged. The Advanced Render feature uses Salesforce APEX syntax to evaluate complex and compound logical statements.

Conditional Logic With Salesforce Formula Fields

You can achieve simple rendering using only Salesforce formula fields. This technique works by using a formula field which returns either text or a blank value based on the conditional logic you set in the formula. That formula field is then simply merged into your S-Docs template just like any other merged field. While this is simple, you may reach the upper size limits of the formula field if you want to show large blocks of text.

For example, dynamically inserting "Terms and Conditions" in your document based on another field value should not be done with a formula field. Moreover, having text and logic split between your template and formula is not a good practice, as this becomes difficult to maintain.

Lastly, if you have many conditions in multiple S-Docs templates, this approach is not practical because it will require too many formula fields to be created. We therefore suggest this approach for only the simplest cases, or where the formula field already exists for other purposes. For example, if you already have a field called "Delivery Charge" and you want it to display "No Charge" for "Gold" tier customers, you may use a formula field like the one below:

[code lang="html"]IF( Tier__c="Gold", "No Charge", Fee__c)[/code]

Conditional Logic With The S-Docs Render Feature: Basic Usage

The S-Docs Render feature provides a mechanism to dynamically show or hide information without having to create additional templates for every use case. You add a render statement into your S-Docs template, and if it evaluates to TRUE, then the entire block (up to the closing ENDRENDER tag) is included; otherwise it is omitted. To use the S-Docs Render feature, you can insert the syntax yourself, or click the Insert Conditional Logic button. This document will focus on editing render syntax yourself.

We'll begin with an example. You may want to display an additional paragraph in your document if the client lives in California. Here is a snippet that you would add to your S-Docs template where you want the text to appear:

[code lang="html"]<!--RENDER='{{!Account.BillingState}}'== 'CA' -->
This is additional information that only pertains to our clients who have a billing address in California
<!--ENDRENDER-->[/code]

The basic S-Docs render feature supports eight basic comparators (==, !=,  >, <, >=, <=, CONTAINS and NOT CONTAINS).

Note: If any fields in your render statement contain words and have a field type anything other than a basic string type (rich text, textarea, longtext, function, etc.) you will need to add the  merge field attribute render. For example, if your merge field looked like this: {{!MyTestField}}
The field with the attribute added would look like this: {{!MyTestField render}} Within a render statement, it would look like this:
<!--RENDER= '{{!MyTestField render}}' == 'Test' -->{{!Opportunity.closedate M/d/yyyy}}<!--ENDRENDER-->
Note that this attribute should only be added to merge fields within render tags (e.g. enclosed by <!-- and -->). In the above example, the attribute  is not added to the {{!Opportunity.closedate M/d/yyyy}} because this merge field is outside of the render tags.
Additionally, note that the Insert RENDER button will not add this attribute automatically. This functionality was added in version 4.48

Render is also useful to determine if a value is empty or NULL. In the example below, we can create two render blocks. Since the value can only be null or NOT null, we are assured that only one of the render blocks below will be included in the final document output:

[code lang="html"]<!--RENDER='{{!Contact.Phone}}'== 'NULL' -->
No Phone Number on recode. Please update.
<!--ENDRENDER-->
<!--RENDER='{{!Contact.Phone}}'!= 'NULL' -->
We have the following phone number: {{!contact.phone}}
<!--ENDRENDER-->[/code]

Finally, render can be used to assess if something is true or false (Boolean fields). Much like the example above, we can create two render blocks- one for true and one for false- and only one of the render blocks will be included in the final document output. If the user selects the true checkbox the document will only render for true and vice versa.

[code lang="html"]<!--RENDER='{{!Contact.Checkbox__c}}'== 'True' -->
This checkbox is checked.
<!--ENDRENDER-->
<!--RENDER='{{!Contact.Checkbox__c}}' == 'False' -->
This checkbox is unchecked.
<!--ENDRENDER-->[/code]

Basic Render and Nested Render Statements

S-Docs provides for 4 levels of nesting render statements. This allows you to place conditions within other conditions. Using nested render statements can also be leveraged to achieve compound logic as shown in the example below:

[code lang="html"]<!--RENDER='{{!Contact.Phone}}'== 'NULL' -->
We don't have a primary phone number
<!--RENDER1='{{!Contact.OtherPhone}}'== 'NULL' -->
<!--RENDER2='{{!Contact.homephone}}'== 'NULL' -->
and there are no alternate phone numbers available
<!--ENDRENDER2-->
<!--ENDRENDER1-->
<!--RENDER1='{{!Contact.fax}}'!= 'NULL' -->
but, there is a fax number: {{!contact.fax}}
<!--ENDRENDER1-->
for this contact!
<!--ENDRENDER-->[/code]

There is no limit on the number of render statements you place within other render statements, however you are limited to nesting them to a maximum of 4 levels deep. Note in the example above that you can have multiple "Render1" tags within the same parent "Render" tag. However, you must change the render tag name whenever you are nesting a render within another render statement. When doing this, you must change the name of the nested render tag to "RENDER1" "RENDER2" or "RENDER3" and this name must be different than any of its parent tags.

Note: Nested render statements cannot skip levels. In other words, RENDER2 cannot come after RENDER; you must follow the RENDER > RENDER1 > RENDER2 > RENDER3 format.
Note 2: Whenever using the S-Docs Render feature, all of your RENDER and ENDRENDER tags must be properly paired and terminated.
Note 3: HTML tags must either fully enclose or be fully enclosed by RENDER and ENDRENDER statements. For example, a <table> tag cannot open outside of a render statement and close inside of one.

Basic Render Without Nesting

S-Docs also uses AND (&&) and OR (||)  in the RENDER statement, so you don't have to nest. A RENDER statement using AND (&&) can be leveraged to achieve logic as shown in the example below:

[code lang="html"]<!--RENDER=('{{!Contact.Phone}}' == '4150000000' && '{{!Contact.fax}}' != '4150000000') -->
We have the defined primary phone number, (415)000-0000, and a fax number that is different than the primary phone number
<!--ENDRENDER-->[/code]

Similarly, OR (||) can be used as shown in the example below:

[code lang="html"]<!--RENDER=('{{!Account.billingstate}}' == 'CA' || '{{!Account.shippingState}}' == 'CA') -->
Either the billing address or shipping address is in California
<!--ENDRENDER-->[/code]

AND (&&) and OR (||) can be used concatenate multiple statements. For example:

[code lang="html"]<!--RENDER=('{{!Contact.Phone}}' == '4150000000' && '{{!Contact.fax}}' != '4150000000') || ('{{!Contact.Phone}}' != '4150000000' && '{{!Contact.fax}}' == '[undefined]') -->
We have either a defined primary phone number, (415)000-0000, and a fax number that is different than the primary phone number, OR a primary phone number, (415)000-0000, and an undefined fax number
<!--ENDRENDER-->[/code]

A similar method using the Runtime Prompt can also show a prompt by letting the user choose to include or to not include the block of text.

'CONTAINS' and 'NOT CONTAINS' Statements

In addition to checking for a string with boolean functions, you can use 'CONTAINS' or 'NOT CONTAINS' to look for a specific string. For example, a statement with 'CONTAINS' would look like:

[code lang="html"]<!--RENDER='{{!Contact.Name}}' CONTAINS 'Tim' -->
Checking for the substring/contact name 'Tim'
<!--ENDRENDER-->[/code]

And a statement with 'NOT CONTAINS' would look like:

[code lang="html"]<!--RENDER='{{!Contact.Name}}' NOT CONTAINS 'Tim' -->
Checking for a substring/contact name other than 'Tim'
<!--ENDRENDER-->[/code]

Uploading Documents to Google Drive

By Documentation, S-Docs GDI: Google Drive Integration No Comments
Note: If you haven't configured the S-Docs and Google Drive integration, please review this article first.

Uploading a Document to Google Drive

When you generate any document that is Google Drive enabled, an Upload Selected to Google Docs button appears above the list of generated documents. Click the button to upload the selected documents.

Authorizing Access to Google Drive

The first time you try to upload a document using S-Docs, you will be presented with S-Docs Authorization page that you saw when setting up the Google Drive integration. Click Authorize Google Drive Access to grant permission for S-Docs to access your account.

 

You will be redirected to a Google-hosted sign-in page. Sign into your Google account now.

Note: If you receive an error at this step, confirm you have completed the S-Docs & Google Drive setup steps correctly.

Once signed in, Google will present a warning. Click Advanced Options and then Go to force.com.

Finally, click Allow.

This step needs to be done only once, as this access authorization is retained with your Salesforce account. Once authenticated, S-Docs uses OAuth 2.0 technology to manage access between S-Docs and Google Drive.

Going forward, the authorization step will be skipped, and you will be directed to the upload confirmation page below.

On this page, you can [1] see which documents are queued for upload, [2] remove individual documents from the queue, and finally [3] click Upload to Google Drive to upload your documents. You can also [4] deauthorize S-Docs from your Google Account by clicking on the Unlink S-Docs from my Google Drive account link at the bottom of the page.

Once you click the Upload to Google Docs button, the Status field will change from “Queued” to a link. The link will open the document directly within Google Drive.

Note: For help uploading S-Docs to specific Google Drive folders, please view this article.

Opening Google Drive Docs Within Salesforce

Links to documents and their icons are updated whenever a document is uploaded to Google Drive. Clicking on the link will open the document directly within Google Drive in either a new tab or new window.

Once a document is uploaded to Google Drive, it can be moved and shared as needed by using standard Google Drive functionality.

Setting Up S-Docs & Google Drive

By Documentation, S-Docs GDI: Google Drive Integration No Comments

Introduction

S-Docs connects seamlessly with Google Drive, meaning that you can generate documents securely on the Salesforce platform and then upload them to Google Drive right away -- all without ever leaving Salesforce. This article will provide you with step-by-step instructions for configuring the S-Docs and Google Drive integration.

The S-Docs package already includes all needed components that allow it to work with Google Drive. However, your admin will need to complete the following steps to enable the feature.

Step 1: Add Remote Site Settings

The S-Docs Google Drive Integration requires that you create two entries in Salesforce’s Remote Site Settings that will allow your Salesforce org to interface with Google.

From the Setup menu, navigate to Remote Site Settings by typing "Remote Site Settings" into the Quick Find bar, then click Remote Site Settings in the dropdown menu. Click New Remote Site.

Enter the following values:

Remote Site Name: SDOCS1
Remote Site URL: https://accounts.google.com

Make sure Active is checked, and then click Save & New.

For the next site, enter the following values:

Remote Site Name: SDOCS2
Remote Site URL:
https://www.googleapis.com

Make sure Active is checked and then click Save.

Step 2: Notify S-Docs Support of API Request Domains

For the S-Docs and Google Drive integration to function properly, S-Docs needs to whitelist the domains that your API requests will be coming from. Please email support@sdocs.com with the following two domains:

1. Your org's domain

To find your domain in Lightning, click your user profile in the upper right corner and copy it from under your username. Make sure to add "https://" at the beginning.

To find your domain in Classic, navigate to the Home screen and copy it from your browser's URL bar up to the first forward slash.

2. Your Google Drive Redirect URI

To find your Google Drive Redirect URI, you need to attempt to authorize S-Docs to upload documents to Google Drive.

Navigate to the S-Docs Setup page by clicking the App Launcher in the upper left corner, typing "S-Docs" into the search field, then clicking S-Docs Setup.

Scroll down to the Other Pages section and click Go To Google Drive Integration Page.

 

On the next page, click Authorize Google Drive Access.

Then, copy the Redirect URI up to the first forward slash.

Email the two URLs from this step to support@sdocs.com. S-Docs will whitelist your domains so that you can get started using Google Drive with S-Docs.

Step 3: Add Google Docs Enabled Checkbox to Template Detail Page & Activate Templates for Google Drive

Administrators are able to determine which documents are eligible for upload to Google Drive with the Google Docs Enabled checkbox. This checkbox is not visible by default, however, and must be added to the template detail page layout.

From the Setup menu, navigate to the Object Manager and find the SDoc Template object.

Navigate to the Page Layouts tab, click the dropdown arrow for the SDoc Template page layout, and click Edit.

Navigate to the Fields tab, find the Google Docs Enabled field, and drag it down into the SDoc Template Detail section. Click Save.

This checkbox will now appear on all template detail records. You can now check it to determine whether new documents generated with this template can be uploaded to Google.

For more information on generating and uploading S-Docs documents to Google Drive, please review our guide Using Google Drive.

Step 4 (Optional): Specify A Google Drive Foler

By default, all S-Docs uploaded to Google Drive will be stored in the user's base Google Drive folder. You can specify a different folder to upload your document to at the template level.

If your template is Google Docs enabled, the Document Options tab in the template editor will contain additional Google Drive options where this can be configured.

[1] To specify which folder documents generated using this template should be stored within, paste the folder ID into this field.

[2] Check this box to upload your document to Google Drive in its native format. By default, all documents uploaded will be converted to Google Docs. This checkbox will cause a PDF to upload as a PDF instead of a Google Doc.

Overview of S-Docs GDI

By Documentation, S-Docs GDI: Google Drive Integration No Comments

Introduction

All paid versions of S-Docs can easily integrate with Google Drive. This Google Drive Integration (GDI) allows documents created using S-Docs to be automatically uploaded to Google Drive and linked seamlessly within Salesforce.

By doing this, the docs are stored on the Google cloud where they can be shared and edited without requiring any additional software (e.g. MS Office) and can also be accessed using mobile devices. By using S-Docs GDI, your Salesforce users do not need to download a file before making their changes nor need to upload the same afterward. This ensures that everyone is working from only one copy of the document and changes are reflected real-time, eliminating the need to track and reconcile any conflicts.

Note: This article provides a broad overview of the S-Docs and Google Drive integration. For instructions on setting up the S-Docs and Google Drive integration, click here. For instructions on uploading documents to Google Drive after the integration has been set up, click here.

Google Drive Overview

Google Drive is a service that allows users to store, collaborate, and share documents in the cloud. Google Drive currently offers 15GB file storage free with the option to purchase more storage. However, it is important to note that S-Docs creates all documents in Google Drive native format. This means that these documents do not (as of this latest update) count towards your Google Drive file storage limit and therefore you can use S-Docs with Google Drive with minimal or no cost.

To learn more about Google Drive, here is a good reference:

https://docs.google.com/document/d/1ZeBmYKmywOygOHfyZI36i68W5tRjHf_OC6WqxIoHQeo/edit

Example Use Case

S-Docs GDI is useful when you have multiple users who you want to collaborate on the same document. For example, let’s say you use S-Docs to generate your standard Contract PDF, which merges your Salesforce Contract record data with your S-Docs Template. For this use case, let’s assume the Contract needs input from the VP of Sales prior to finalization. Once the user generates the Contract document, they would optionally click one button to upload that document to a shared Google Drive repository. When the VP clicks on the document link within Salesforce, rather than downloading and opening MS Word, the VP would be able to view and make changes directly to the contract using just their browser. When the document is finalized, Google allows you to export it to other formats, such as PDF, before distribution.

Intended Audience

This guide provides solutions and ideas to help organizations get the most out of S-Docs. It is intended for users already familiar with Salesforce administration and configuration techniques. Knowledge of HTML is also useful in creating the highest quality documents. We encourage you to visit our website for template samples and help.

Security Consideration

Unlike S-Docs, which works entirely within the Salesforce.com platform, using the Google Drive Integration means your documents are hosted remotely.

  • Your documents may contain sensitive data.
  • If there is a disruption in Google Drive service, your documents will not be available even if there are no issues with Salesforce.com.
  • Google Drive has its own Terms of Service concerning use and confidentially, which differ from Salesforce.com.
  • S-Docs uses OAuth2.0 to exchange user credential information between Salesforce and Google. This process requires that a user grant access to their Google Drive account.
  • Google may make future changes to its Google Drive APIs that unexpectedly render it incompatible with S-Docs. While we do not expect such a change, and would make every reasonable effort to continue to support the Google Drive service, we cannot guarantee future compatibility because of this reason.

Your security team would need to determine if this is an acceptable risk.

Allow S-Docs Jobs & API Calls to be Run as Another User

By Documentation, S-Docs Automation: Jobs & REST API No Comments

Introduction

This document is intended as an additional reference for allowing S-Docs Jobs to be run as a specified user. Click here for the complete guide to automating S-Docs with S-Docs Jobs.

Running S-Docs Jobs as any user is simple; getting Salesforce to allow this, however, is a bit more work. This document discusses how you can get Salesforce to allow you to run S-Docs Jobs as another user and configure Process Builder to run as another user. This setup uses JWT Bearer assertion flow to run as any user without preauthorization. The steps include adding remote site settings, creating a connected app, and linking the app details to S-Docs via a custom settings entry.

Video Tutorial

Step 1: Create Remote Site Settings

From the setup menu, type "Remote Site Settings" into the Quick Find bar, then click Remote Site Settings in the dropdown menu.

  1. Click New Remote Site. For Remote Site Name, enter whatever you'd like. For Remote Site URL, enter:
    • For production: https://login.salesforce.com
    • For sandbox: https://test.salesforce.com

Ensure that the Active checkbox is checked, and click Save.

  1. Click New Remote Site again. For Remote Site Name, enter whatever you'd like. For Remote Site URL, enter your Salesforce domain URL.
    Note: In Classic, you can copy your domain from your address bar, e.g. https://na1.salesforce.com or https://cs2.salesforce.com. In the URL, note that the number after na or cs will vary.
    In Lightning, you can copy your domain by clicking your user profile in the upper right corner, and copying it from under your username. Note that you need to add "https://" at the beginning.

Ensure that the Active checkbox is checked, and click Save.

  1. If you are using S-Docs with Communities with a custom domain, you should add a new remote site for your custom domain as well.

Step 2: Create a Self-Signed Certificate

From the setup menu, type "Certificate" into the Quick Find bar, then click Certificate and Key Management in the dropdown menu. Click Create Self-Signed Certificate.

Name your certificate SDocsCert. Click Save.

Click Download Certificate, and keep track of where the file is stored. We will use this in the next step.

Step 3: Create A New Connected App

Navigating to the Connected App creation page is a bit different in Classic and Lightning. In Lightning, type "App Manager" into the Quick Find bar in the setup menu, then click App Manager in the dropdown menu. Click New Connected App in the top right.

In Classic, type "Apps" into the Quick Find bar in the setup menu, then click Apps in the dropdown menu (under Build > Create). Scroll down to the Connected Apps section and click New.

In the Basic Information section, fill in the following fields:

Connected App Name: Sdocs Connected Apps
API Name: Sdocs_Connected_Apps
Contact Email: support@sdocs.com

Scroll down to the API (Enable OAuth Settings) section and check Enable OAuth Settings. Then, enter one of the following URLs into the Callback URL field, depending on if you're working in a sandbox or production environment:

Production: https://login.salesforce.com/services/oauth2/callback
Sandbox: https://test.salesforce.com/services/oauth2/callback

Next, check the Use Digital Signatures checkbox and upload the self-signed certificate that you downloaded in step 2.

Then, scroll down to the Selected OAuth Scopes field. Add the following scopes to your selected scopes:

  • Perform requests on your behalf at any time
  • Access and manage your data
  • Access and manage your Chatter data

This section should look similar to the following image when you are finished:

Leave the rest of the fields at their default settings, and click Save. You will be redirected to the Connected App detail page. Scroll down to the API (Enable OAuth Settings) section and click Copy next to the Consumer Key field. Paste this somewhere you can access later. You will use this key in Step 4. Then, click Manage at the top of the page.

On the next page, click Edit Policies.

Scroll down to the OAuth Policies section. Set the Permitted Users field to Admin approved users are pre-authorized. Set the IP Relaxation field in accordance with your organization's policies. Keep the Refresh Token Policy set to Refresh token is valid until revoked. Then, click Save.

Next, scroll down to the Profiles section and click Manage Profiles.

Add all user profiles that will generate documents, or be used as the "Run As" user. Click Save.

Note: We recommend only setting system administrators to "Run As" users.

Step 4: Create A New Custom Setting Entry

From the setup menu, type "Custom Settings" into the Quick Find bar, then click Custom Settings in the dropdown menu. Find SDocsSettings and click Manage.

If you've created an S-DocsSettings entry in the past, you can click the Edit link next to its name to edit it now. Otherwise, click New to create a new SDocsSettings entry.

Fill in the following values:

Name: SDocsSettings
ConnectedAppCertificateName: SDocsCert
ConnectedAppConsumerKey: Paste the consumer key that you copied in step 3
ConnectedAppLoginURL:
[Production]: https://login.salesforce.com
[Sandbox]: https://test.salesforce.com

Note: If you are using Salesforce Government Cloud, use your MyDomain URL instead of the URLS listed above.

ConnectedAppTokenURL: Paste your Salesforce domain URL. If you're not sure how to find it, refer to Step 1
ConnectedAppUserName: If you are configuring S-Sign e-signatures, enter a username to be used as the S-Sign Internal User (we recommend using an administrator's user name). The S-Sign Internal User will be the user which all S-Sign operations will be conducted by through the secure S-Docs Connected App.

Note: If you are using Salesforce Government Cloud, you also need to fill in the ConnectedAppAudienceURL field with one of the URLs listed below. This field sometimes populates with your MyDomain URL, which should not be used for this field. If your MyDomain URL populates this field, replace it with one of the 2 URLs listed below.

ConnectedAppAudienceURL:
[Production]: https://login.salesforce.com
[Sandbox]: https://test.salesforce.com

Your SDocsSettings entry should look similar to the following:

 

Click Save.

Step 5: Configure Your Salesforce Process, Apex Trigger, or Flow

The last step is to configure your Process, Apex trigger, or flow to populate the Run As User field on the S-Doc Job object . Please refer to the "Fields For Our Use Case" section in this article to learn more about S-Doc Job fields.

For example, if you were automating your document generation process with Process builder, you would need to add the Run As User field, set the Type to string, and enter the username of the user to be used as the running user. This is displayed in the following image:

Note: We recommend only setting system administrators to "Run As" users.

For more information on automation and S-Docs jobs, please refer to our automation guides for Salesforce Lightning or Salesforce Classic.

Upon completion, you should be able to invoke the call using any username. To verify the process, you can go to:

Setup > Administrations Setup > Monitoring > Apex Jobs.

If you require additional error handling, this should be done within your own code base.

My Self-Signed Certificate is Expiring Soon!

Several months after setting this up, you may get an email from Salesforce informing you that your self-signed certificate expired. If that is the case, you can follow the steps below to renew your certificate. We recommend doing this after hours.

1. From the setup menu, type "Certificate" into the Quick Find bar and click Certificate and Key Management in the dropdown menu.
2. Click Delete for SDocsCert.
3. Click Create Self-Signed Certificate.
4. Set Label to SDocsCert.
5. Set Unique Name to SDocsCert.
6. Click Save.
7. Click Download Certificate.

The next steps are different in Salesforce Classic and Salesforce Lightning.

For Classic:

1. From the setup menu, type "Apps" into the Quick Find bar, then click Apps (under Build > Create).
2. Scroll down to the Connected Apps section, find "Sdocs Connected Apps," and click the Edit link next to it.
3. Scroll down to Use digital signatures.
4. Click Choose File and select the previously downloaded certificate.
5. Click Save.
6 It may take several minutes for the new certificate to take affect.
7. Confirm that everything is working (test SDJobs with Mass Merge).

For Lightning:

1. From the setup menu, type "App Manager" into the Quick Find bar, then click App Manager in the dropdown menu.
2. Find the "Sdocs Connected Apps" connected app. Click the dropdown arrow on the right, and click View.
9. Click Edit at the top of the page.
11. Scroll down to Use digital signatures.
12. Click Choose File and select the previously downloaded certificate.
13. Click Save.
14. It may take several minutes for the new certificate to take affect.
15. Confirm that everything is working (test SDJobs with Mass Merge).

Troubleshooting

If you performed this setup but your S-Docs Jobs are stuck at Error - Run As User Failed, or 10%, please try the following:

  • Navigate to Setup > Custom Settings > SDocsSettings > Manage > SDocsSettings > Edit, and set ConnectedAppTokenUrl to the URL domain seen in your browser's URL bar when you're on the "home" page in Classic. Additionally, set the ConnectedAppLoginURL to one of the following:
    • Production: https://login.salesforce.com
    • Sandbox: https://test.salesforce.com
  • Navigate to Setup > Connected Apps > SDocs Connected Apps > Profiles, and verify that the profiles of the following users are added to the app's permitted profiles list:
    1. The user who inserted the job
    2. The 'Run As User'
  • Go to Setup > Remote Site Settings and verify that there are entries for the appropriate Salesforce production/sandbox URL and the customer’s home URL (Salesforce Classic). Additionally, verify that these entries are active.
  • Make sure the user's profile has the Apex REST Services permission checked.

Automation & Batch Processing Using S-Docs Jobs

By Documentation, S-Docs Automation: Jobs & REST API No Comments

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:

Name: SDocsSettings
ConnectedAppLoginURL:
Production: login.salesforce.com
Sandbox: test.salesforce.com
SD Jobs Batch Size: 45
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).

Introduction

If you're looking for a way to automate your document generation process--perhaps you want a document to be automatically generated and emailed when a field value has changed or a date has passed--this document will help you configure S-Docs to meet your requirements using the S-Docs Jobs object.

For example, when a user changes an opportunity stage field to “send quote,” you can configure S-Docs to generate a PDF quote along with a customized cover letter and email it to the opportunity contact. Users would not need to click on any buttons or choose any templates. Whenever the field value is changed, even from a mobile device, the process is invoked and the documents are generated and optionally emailed.

This document will show you how to use S-Docs Jobs to automate document generation in three different ways: with Salesforce Process Builder, APEX Triggers, and Visual Workflows.

If you are looking for a way to generate multiple S-Docs (in batch) from an object list view, you can accomplish this with S-Docs Jobs as well. For example, a user could select multiple records at once from a list view and send each record a custom invitation email to an event. The possibilities to further automate and distribute your documents are unlimited. Please refer to this documentation for more information about batch document generation.

Automatic Document Generation with S-Docs Jobs

An S-Docs Job is a simple, intuitive Salesforce object designed for automatically generating (and optionally emailing) documents with your custom code, Salesforce Processes, Salesforce Flows, and other integrations. We recommend you use S-Docs Jobs with Process Builder, which can do just about anything workflows can.

For use with your custom code, Salesforce Processes, or Salesforce Flows, the API name for S-Docs Jobs is SDOC__SDJob__c, and the API names for some of its relevant fields can be found in the following list. You'll use these fields later when configuring your document automation.

To automatically generate S-Docs with S-Docs Jobs, you'll be configuring your Salesforce Process, custom code, or Visual Workflow to do at least five things:

  1. Create an S-Docs Job record
  2. Specify the ID of the record you would like to generate these documents for
  3. Specify this record’s object API name (Opportunity, Account, etc.)
  4. Specify the name of the template you would like to use for document generation
  5. Optionally fill in the fields for emailing these documents. Finally, you will need to set the SDOC__Start__c field for this Job record to “true” in your APEX code or Salesforce flow to run this Job (i.e. to generate and optionally email the specified documents)

Before we see how to use S-Docs Jobs for automatic document generation, we’ll see what the Job records themselves look like.

Behind the Scenes of S-Docs Jobs

When one of the three methods (Salesforce Processes, APEX code, or Visual Workflows) creates an S-Docs Job, it is stored as an S-Docs Jobs record. To view these records, navigate to All Tabs ("+" icon), then scroll down and click S-Docs Jobs.

All S-Docs Jobs records appear here. In most (if not all) cases, we will not be creating Jobs records with the New button here; the records here should be created by your Salesforce Process, APEX triggers, Salesforce flows, etc. However, you can delete logs by opening a job record and clicking Delete (though this may also be done programmatically).


You can open a job record by clicking on the SDJob number on the left. The record will show you things like the IDs of the templates used to generate it (i.e. the Doclist), the ID of the record it generated documents for (i.e. the Object ID), and other relevant Jobs fields.


The documents the Job generated will also be included in the record. You can click on their icons under the Job Execution Details section to view them. You don't need to find the job record to view documents generated by a job, however. A related list for these documents will be automatically created on the page of the record you generated the documents for. For example, if we created an APEX trigger that would create a Job to generate three documents whenever an account record was created, we would see those three documents in that account record’s related list like so:

Note that these documents would still exist in the S-Docs related list on the account record page even if we deleted the Job that created these documents. If you wanted to delete these documents for good, you could delete them from the S-Docs related list.

Now that we’ve seen how S-Docs Jobs work behind the scenes, we can see how we might leverage their functionality with Salesforce Processes, APEX triggers, and Salesforce flows.

Use Case: Automatically Generating & Emailing a Welcome Letter Whenever an Account is Created

Consider the following use case: whenever an account is created, we would like S-Docs to generate a welcome letter for that account, and then email it to a contact associated with that account. This process can be automated in no time using S-Docs Jobs! In the three sections following this one, we will explore how to accomplish this in Process Builder, APEX triggers, and in Salesforce Flows (Visual Workflows). In all three of these scenarios, we will have to fill in the following fields in order to automate this particular case; you'll see how to use these fields once we get into each scenario.

Fields for our Use Case

SDOC__Start__c (Start Job)This will be set to ‘true’ so that the specified documents will automatically generate (and in this case, automatically email, as we have specified them to do so using the Job’s email fields) upon the creation of this particular S-Doc Job record.

SDOC__SendEmail__c (Send Email)If we set this to ‘0,’ an email will not be sent. If we set it to ‘1,’ this S-Doc Job record will email the document it generated. Thus, we will be setting this to ‘1.’

For this to work properly, our Doclist needs to include an S-Doc HTML email template. In our example, this template will use a merge field in the "Email SentTo" field (found under the Email Settings tab of the template editor) that will be dynamically populated with the appropriate contact's email address. Then, each Job record would generate a welcome letter PDF, generate an email using the HTML email template, attach the welcome letter PDF to that email, and then send that email.

SDOC__Oid__c (Object ID): This is the Object ID field, i.e. the place where we specify which object our Process/APEX Trigger/Flow should pull record IDs from. In our example, we will choose Account, since we want our process to use Account record IDs.

SDOC__ObjAPIName__c (Object API Name)This is the API name of our objects. In our example, we’re creating this trigger for new accounts, so we'll store Account in this field.

SDOC__Doclist__c (Doclist): This is the comma-delimited list of S-Docs template names that we will be using to generate our documents. Make sure there aren’t any spaces in your comma-delimited list. In our example use case, Welcome Letter is the name of our S-Docs PDF welcome letter template, and Email Template is the name of our S-Docs HTML email template. Thus, we will be using the following Doclist for our example use case Salesforce Process, APEX code, and Salesforce Flow:

Welcome Letter,Email Template

You can also use template IDs for the doclist parameter, however this is not recommended because these IDs will change between sandbox and production orgs, meaning that you will have to re-add the new template IDs into this parameter after transferring to production.

To find the template IDs for use in your Doclist field, go to the template record page for each template you're using.


The template ID can be found in the URL. You can then copy and paste this ID into your Doclist field for an S-Docs Job in your Process, APEX code, Flow, etc.

Note: If your org contains multiple templates with the same name, all of them will generate if one of them is referenced in one of your processes. In this case, you should use the template ID instead.

In the following three sections, we will see how to use S-Docs Jobs with Salesforce Processes, APEX triggers, and Salesforce Flows to automatically generate and email a welcome letter whenever an account is created.

Additional Fields

While the example use case in this article only uses 5 fields, S-Docs Jobs also support a number of other fields that you can use to further customize your process.

Email From

Email From allows you to set an org-wide email address as the From address when your S-Docs Job process includes emailing a document.

Email Params

Email Params allows you to add advanced email parameters to your process that are not available to access through standard fields on the S-Docs Job object, such as useExistingNoContactRecord=true.

Incl. Attachments with Email

Incl. Attachments with Email allows you to specify a comma-delimited list of Salesforce Attachment IDs to be included in the email sent out by the S-Docs Job.

Incl. Documents with Email

Incl. Documents with Email allows you to specify a comma-delimited list of Salesforce Document IDs to be included in the email sent out by the S-Docs Job.

Incl. Files with Email

Incl. Files with Email allows you to specify a comma-delimited list of Salesforce File IDs to be included in the email sent out by the S-Docs Job.

Include All Related Files

Include All Related Files allows you to opt to attach every file related to the base record to the email sent out by the S-Docs Job.

Using S-Docs Jobs with Process Builder

The easiest way to generate and email a welcome letter whenever an account is created is to use an S-Docs Job in a Salesforce Process. From the Setup menu, type "Process Builder" into the Quick Find / Search bar and click Process Builder.

Click New in the upper right corner to create a new process.

You can name the process whatever you want, then choose to have this process start when a record changes. Click Save.


Click Add Object, choose Account, and start the process only when a record is created.


Click Save. Then, click Add Criteria and set it to No Criteria, since we want our Job to execute every time a new account record is opened.

Then, click Add Action and choose Create a Record for our Action Type. For the Record Type, select SDoc Job. You may have to type it in to find it.

A Field Values menu will appear below. This is where you will add the five fields described above in the Fields for Our Use Case section. Click Add Row to add each new field.

Then, we click Save and click Activate at the top right of the screen.

All done! S-Docs will now automatically generate and email a welcome letter whenever an account is created.

Using S-Docs Jobs with APEX Triggers

S-Docs Jobs are also simple to use with APEX triggers. To get started, click your username in the upper right corner, then click Developer Console.

Then, navigate to File > New > Apex Trigger.

You can name the trigger whatever you want, then select Account for the sObject.

You'll see the following screen.

You can delete the text here, then copy and paste the following APEX trigger into the text field.

[code lang="html"]trigger SendWelcomeLetter on Account (after insert) {
List<SDOC__SDJob__c> jobList = new List<SDOC__SDJob__c> {};
for(Account acct : Trigger.New) {
SDOC__SDJob__c job =
new SDOC__SDJob__c(SDOC__Start__c=true,
SDOC__Oid__c=acct.Id,
SDOC__ObjApiName__c='Account',
SDOC__SendEmail__c='1',
SDOC__Doclist__c='Welcome Letter,Email Template');
jobList.add(job);
}
insert jobList;
}[/code]

This simply creates a Job Object in the APEX trigger, fills in its fields as previously discussed in the Fields for our Use Case section above, and inserts each Job into our Salesforce database. Note that SDOC__SendEmail__c is a string, so its value must be specified in single quotes. SDOC__Doclist__c and SDOC__ObjApiName__c must be specified in single quotes as well.

SDOC__Oid__c, the Object ID field, is given the value acct.Id. This means that for each account record in our loop, the S-Doc Job created for this particular account record will have this account record’s ID stored in its SDOC__Oid__c field.

Click File > Save to complete your APEX Trigger!

Using S-Docs Jobs with Salesforce Flows (Visual Workflows)

This option is a special case; say we don’t want to generate an email letter whenever an account is created anywhere in our org. Rather, we would like to generate and email a welcome letter only when an account record is created in a Salesforce Flow. Using S-Docs Jobs with Salesforce Flows is as simple as using any other object with Salesforce Flows, so this is easy to accomplish. To get to Flow Builder, type "Flows" into the QuickFind / Search bar in the Setup menu, click Flows, then click New Flow.

Create an Autolaunched Flow.

First, we need to create a new variable called “acct.” Select Manager in the Toolbox area, then click New Resource.

For the Resource Type, select Variable. Enter "acct" for the API name, and make sure the Data Type field is set to Text.

Now we need to create two Record Creates: one for an Account and one for an SDoc Job. We'll create the Record Create for an Account first. Navigate back to the Elements tab in the Toolbar, then drag Create Records into the Flow.

Insert the following information:

Label: Create Account
API Name: Create_Account
How Many Records to Create: One
How to Set the Field Records: Use separate variables, resources, and literal values
Object: Account
Field: Name
Value: New Account Example
Variable: {!acct}

Next, we need to add a Record Create for the SDoc Job. Drag Create Records into the flow again. Insert the following information:

Name: Automatically Generate and Email Welcome Letter
Label: Automatically_Generate_and_Email_Welcome_Letter
How Many Records to Create: One
How to Set the Record Fields: Use separate variables, resources, and literal values
Object: SDoc Job

Fields & Values:

SDOC__Start__c: {!$GlobalConstant.True}
SDOC__SendEmail__c: 1 (This specifies that we wish to email the document generated by this Job record (we would type in “0“ (without quotes) if we did not wish to send an email)
SDOC__Oid__c: {!acct} This variable stores the ID of the Account record created when the “Record Create” that we made for an Account executes.
SDOC__ObjApiName__c: Account
SDOC__Doclist__c: [Insert your template names here]

Once you've saved both record creates, attach them together by clicking the circle on "Create Account" and dragging the line to the circle on "Automatically Generate and Email Welcome Letter," and attach "Start" to "Create Account."

At this point, running this flow would result in an account called “New Account Example” being created, and documents for this account would automatically be generated and emailed by the S-Doc Job record created for this account.

If we wanted to, we could now start building a much larger flow involving these two Record Create boxes.

Batch Processing with S-Docs Jobs (Recommended)

S-Docs Jobs are also used to facilitate batch document processing. However, they are used behind the scenes throughout the entire process; batch processing is performed in a simple click-only interface, so you won’t have to worry about creating the Jobs themselves. This feature, in addition to the mass merge feature, is covered in detail in the S-Docs Mass Merge & Batch Document Feature documentation.

Mass Merge & Batch Document Feature

By Documentation No Comments

Introduction

When you leverage the S-Docs Mass Merge 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.

Video Tutorial

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. Here, we can select up to 2 templates that we would like to use for this mass merge (note that the Combine all into single printable document button only supports the selection of one template). In this case, we'll select the Account Past Due template, then click Go To Next Step.

On this page, we can review all of the records that we added to the mass merge list. We've added the mailing information for each of our contacts displayed in this list, but you can add any combination of relevant fields. Once we're satisfied with the records, we can click Start Mass Merge. A unique document will generate for each record in our 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 also attached to the record it was generated for; if we go to the contact record page for “Jack Rogers,” 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.

The pencil icon under the Edit Link column can be clicked to Live Edit any document in this list. This icon will only appear if the template you chose is Live Edit enabled.

At this point, we click the Combine all into single printable document button in order to combine all of the generated documents into a single PDF file.

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 print mailing labels, we simply select a label template and click Print Labels/Envelopes to download a single DOC containing all of the mailing labels for easy printing.

Note: 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 Visualforce page for each object you are setting up mass merge on.

Create a new Apex class. To get this page, navigate to the Setup menu and type Apex Classes into the Quick Find bar. Click Apex Classes (under Custom Code) and then click New.

Paste in the following code (you only need to create this class once):

[code lang="html"]public class SDAddToMassMerge {
private ApexPages.StandardSetController stdSetController;

public SDAddToMassMerge(ApexPages.StandardSetController sscOther) {
stdSetController = sscOther;
}

public PageReference createMassMergeJobs() {
String objectName = ApexPages.currentPage().getParameters().get('objectName');
Boolean showHeader = ApexPages.currentPage().getParameters().get('showHeader') != 'false';

List<SDOC__SDJob__c> addToMassMerge = new List<SDOC__SDJob__c>();
List<SObject> selectedRecords = stdSetController.getSelected();
if (Test.isRunningTest()) {
selectedRecords = new List<SObject> { new Contact(LastName='Test') };
}
for (SObject selectedRecord : selectedRecords) {
SDOC__SDJob__c massMergeJob = new SDOC__SDJob__c(
SDOC__Oid__c = String.valueOf(selectedRecord.get('Id')),
SDOC__runAs__c = UserInfo.getUserName(),
SDOC__Status__c = 'Selected',
SDOC__type__c = 'Bulk Job - List View',
SDOC__objAPIName__c = objectName
);
addToMassMerge.add(massMergeJob);
}
insert addToMassMerge;

Integer batchSize = Database.countQuery(
'SELECT COUNT() FROM SDOC__SDJob__c WHERE ownerid=\''
+ String.valueOf(UserInfo.getUserId()) + '\''
+ ' AND SDOC__Type__c=\'Bulk Job - List View\''
+ ' AND SDOC__ObjApiName__c=\'' + objectName + '\''
);

PageReference massMergePage = new PageReference(
+ '/apex/SDOC__SDJobContact'
+ '?numRecordsAdded=' + String.valueOf(addToMassMerge.size())
+ '&batchSize=' + batchSize
+ '&objectName=' + objectName
+ '&showHeader=' + showHeader
+ '&sidebar=false'
+ '&tab=2'
);
return massMergePage;
}
}[/code]

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 the Setup menu and type Visualforce Pages into the Quick Find bar. Click Visualforce Pages, then click New.

Create a new Visualforce page 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.

[code lang="html"]<apex:page standardController="OBJECTAPINAME" showHeader="false"
extensions="SDAddToMassMerge"
recordSetVar="selected"
action="{!createMassMergeJobs}">
<div style="display:none;">
<apex:pageBlock >
<apex:pageBlockTable value="{!selected}" var="r">
<apex:column value="{!r.Id}" />
</apex:pageBlockTable>
</apex:pageBlock>
</div>
</apex:page>[/code]

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 Check__c, your Visualforce Page should look like this:


If you require test coverage for the SDAddToMassMerge class, you can use the following test class (replacing all references to Opportunity with your object):

[code lang="html"]@isTest
private class SDAddToMassMergeTest {
@isTest
private static void SDAddToMassMergeTest() {
Integer numJobsToCreate = 20;
List<Opportunity> selectedOpportunities = [
SELECT Id, Name
FROM Opportunity
LIMIT :numJobsToCreate
];
ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(selectedOpportunities);
ssc.setSelected(selectedOpportunities);
SDAddToMassMerge sdatmm = new SDAddToMassMerge(ssc);
String objectNameTest = '[SDAddToMassMerge Test]';
sdatmm.createMassMergeJobs();
Integer numJobsCreated = Database.countQuery(
'SELECT COUNT() '
+ 'FROM SDOC__SDJob__c '
+ 'WHERE SDOC__ObjApiName__c=\'' + objectNameTest + '\''
);
// System.assert(numJobsCreated == numJobsToCreate);
}
}[/code]

To recap:

  • Create only one Apex class
  • Create a Visualforce page for each object (and later a button for each object)

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.

In Salesforce Lightning, simply navigate to Setup > Object Manager > Your Object > Buttons, Links, and Actions > New Button or Link.

In Salesforce classic, the instructions for custom and standard objects are a bit different.

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 the Setup menu and type Objects into the Quick Find bar. Click objects, then find the name of the custom object that you would like to use in a mass merge. Click the name of the 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.

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.

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 the Setup menu and type the name of your standard object into the Quick Find bar. Find and click on Buttons, Links, and Actions in the dropdown menu. Then, click New Button or Link.

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:

[code lang="html"]/apex/SDAddToMassMergeCHANGE_TO_YOUR_OBJECT_NAME?objectName=CHANGE_TO_YOUR_OBJECT_API_NAME[/code]

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.

In Salesforce Lightning, simply navigate to the object manager page for your object and click Search Layout for Salesforce Classic in the sidebar. Find the List View layout and click Edit, then add the Add To Mass Merge List button to the layout.

In Salesforce classic, the instructions for custom and standard objects are a bit different.

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.) Adding buttons to search layouts for a custom object

Navigate to the Setup menu and type Objects into the Quick Find bar. Click Objects, then find the name of the custom object that you would like to use in a mass merge. Click the name of the object (do not click the edit button). In this example, we will be using the Check object.

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 the Setup menu and type the name of your standard object into the Quick Find bar. Find and click on Search Layouts in the dropdown menu. Then, click Edit next to the layout titled “[Object Name] List View,” where [Object Name] is the name of your object (excluding brackets).

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:
Name: SDocsSettings
ConnectedAppLoginURL:
Production: https://login.salesforce.com
Sandbox: https://test.salesforce.com
SD Jobs Batch Size: 45
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

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 records 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. In Salesforce Lightning, navigate to your object's tab. In this example, we will be navigating to the tab for our Check object. Under List View Controls (represented by a cog), click New.

Enter a descriptive view name. The list API name will auto-populate.

The filters menu will pop up. Change the Filter By Owner field to All Checks.

Next, click New Filter. Set the Field to Amount, the Operator to less than, and the Value to 10000. Then click Save. This means that our list will only include Checks written for amounts of less than $10,000.

Next, click the List View Controls again, then click Select Fields To Display.

Choose your fields. In this case, we'll add Payable To and Amount.

To do the same in Salesforce classic, navigate to the tab for your object. Our Check object 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:

Click Create New View on our Object’s page:

On this screen, you can enter your View Name, Filters, and Fields to Display.

You will be redirected to the resulting List View. In our Check Example, our list does not contain checks 2 or 3 as their “Amount” fields are greater than or equal to $10,000. Click the checkbox on the right 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 “Payable To” and “Amount” 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 Salesforce User. Since we included the “Payable To” field as a column, we don’t have to open all three records to see which one will be paid to Salesforce User; 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.

STEP 5: Use the Mass Merge & Batch Document Feature

Before we use the mass merge and batch document feature, you should make sure that the list of S-Docs Jobs logs is clear. This isn't required, but helps keep the system clean. S-Docs Job records are created when you add records to a mass merge list; by default, they are not deleted after every mass merge. You can choose to enable this functionality in the template editor for the template that you're using with mass merge under the document options tab. Otherwise, let’s see how we can clean up the S-Docs Jobs log list manually. Navigate to the S-Docs app and click over to the S-Docs Jobs tab.

Select any jobs and click Delete Logs.

Now we can perform our mass merge. Navigate to 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

This will bring you to the Mass Merge page. You'll begin on the Add Records tab, where you can modify the records you'd like to include in your mass merge. Note that records in your mass merge list won't be "checked" on this page; a complete list of records in the list can be viewed on the Generate Docs tab.

If everything looks correct, you can click over to the Choose Templates tab to choose your template.

First, [1] select the template you would like to use. You can select one document template and one HTML email template. If your template list is extensive, use the tools above to filter templates by category or keyword. Then, [2] click Go To Next Step. You can also [3] click on the Generate Docs tab to go to the next step; both buttons will take you to the same place. The tabs make it convenient to jump between different steps. The Generate Docs tab will appear as follows.

As you can see, [1] the records we selected are listed in the mass merge list. To begin the process, [2] click Start Mass Merge. When you click this button, you'll be able to [3] view the status of each document as it generates. If the template is Live Edit enabled, [4] the Edit Link column will populate with pencil icons when the documents are finished generating, allowing you to edit each one individually.

If you want to log an activity on each record, [5] check this box.

Once this mass merge is complete, [6] the Combine all into single printable document button will become available. This button is pretty self-explanatory: when you click it, all of the documents that were generated will be combined into a single consolidated document. You can configure settings for this under the document options tab in the template editor for the template that you're using with mass merge. Finally, [6] click Start over (clears selections) if you want to return to the beginning of this process.

Here's what your finished mass merge will look like.

Both records have a Status Link of 100%, meaning both checks successfully generated. You can now click the PDF icon next to each one to view the documents. Additionally, the COMBINE ALL into single printable document button is no longer grayed-out. Let's click this button.

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.

Special Use Cases

Customize Mass Merge with Apex Parameters

You can customize the behavior of the Add To Mass Merge List button by adding certain apex parameters to the pagereference section of your Mass Merge apex class. The table below explains the parameters. Refer to the image below the table for guidance on adding these parameters to your own mass merge class.

Parameter

Values

Function

doclist= Comma delimited list of S-Docs template IDs.
Example: '&doclist=a034P00000an8Q1QAI'

This parameter will auto-select templates to use in the mass merge.

autostart=

True to enable, false to disable (disabled by default).

This parameter will automatically start the mass merge. It must be used in conjunction with the doclist parameter.

tab= 3

This parameter will open the Mass Merge Generate Docs tab upon page load.

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, click Go to Next Step 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:

[code lang="html"]<br />
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cstyle%20type%3D%22text%2Fcss%22%3Etd%20%7Bfont-family%3A%20Arial%2C%20sans-serif%3B%20font-size%3A%209pt%3B%20width%3A2.625in%3B%20height%3A1.0in%3B%20overflow%3Ahidden%3B%20white-space%3A%20nowrap%3B%7D%20%0Atable%20%7Btable-layout%3A%20fixed%3B%20overflow%3Ahidden%3B%20border-collapse%3A%20collapse%3B%20margin%3A0px%3B%20padding%3A0px%3B%20spacing%3A0px%3B%20cell-spacing%3A0px%3Bcell-padding%3A0px%3B%7D%0Adiv%20%7Boverflow%3Ahidden%3B%7D%0A%3C%2Fstyle%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="&lt;style&gt;" title="&lt;style&gt;" />
<!--{{! <LineItemsSOQL>
<class>none</class>
<prefix>
<table>
<tr>
</prefix>
<soql>Select name, mailingstreet,mailingcity, mailingstate, mailingpostalcode from contact where id in
(select SDOC__Contact__c from SDOC__SDJob__c where ownerid = '{{!User.id}}')</soql>
<column prefix="<td><div><table><tr><td>" nullprefix="<td><div><table><tr><td>" newrow="3">name</column>
<column prefix="<br />" nullprefix="<br />">mailingstreet</column>
<column prefix="<br />" nullprefix="<br />">mailingcity</column>
<column prefix=", ">mailingstate</column>
<column prefix=" " postfix="</td></tr></table></div></td>" nullpostfix="</td></tr></table></div></td>" >mailingpostalcode</column>
<postfix>
</tr>
</table>
</postfix>
</LineItemsSOQL> }}-->[/code]

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

On the mass merge page, click over to the [1] Mailing Labels tab, [2] select your mailing label template, then [3] click Print Labels/Envelopes.

This will generate and download a printable mailing label.

mass merge - mailing (2)

Mass Merge Archive

In the Mass Merge Archive tab, you can find previously generated mass merge documents. You can click the PDF icon to view, print, or download these documents.

Automating The Mass Merge Process

If your use case involves:

  1. Selecting all records from a list view (not selecting certain records and excluding others)
  2. Combining the generated documents into a single document

You can automate this process by using a template with a special LineItemsSOQL statement that generates a component template for each record returned by the statement, in place of the Mass Merge feature.

For example, the following LineItemsSOQL statement would generate an Account Summary template for each overdue Account record.

[code lang="html"]<!--{{!<LineItemsSOQL>
<component>Account Summary</component>
<splitEvery>30</splitEvery>
<soql>SELECT Id FROM Account WHERE Overdue__c=true</soql>
</LineItemsSOQL>}}-->[/code]

Each Account Summary would be included in one single consolidated document. This template could then be used in an S-Docs Jobs workflow, or with a one click button to achieve the desired level of automation.

Note: <splitEvery> tags are used to avoid platform limitations for large numbers of records; in this case, processing will be broken up in chunks of 30 records at a time.

Click here to learn more about this feature.

Appendix

Finding the API names for Your Standard Object’s Fields

In Salesforce Lightning, navigate to the Setup Menu, then find your object in the Object Manager. Navigate to the Fields and Relationships tab. All of the field API names will be available under the Field Name column.

In Salesforce Classic, 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 in the section below.

Finding the API names for Your Custom Object’s Fields

In Salesforce Lightning, navigate to the Setup Menu, then find your object in the Object Manager. Navigate to the Fields and Relationships tab. All of the field API names will be available under the Field Name column.

In Salesforce Classic, navigate to Setup > Build > Create > Objects and click the name of your object (do not click the Edit button).

On the page for your custom object, scroll down to the “Standard Fields” and “Custom Fields & Relationships.” The API names for [1] Standard Fields will be located under the Field Name column, and [2] the API names for Custom Fields will be located under the API name column.

Set Apex Class Access from Profiles

If users are unable to access the mass merge page, you may need to add their profile to the mass merge apex class. Click here for instructions on how to do so.

Top