If you are looking for a way to generate multiple S-Docs (in batch) from an object list view, or 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.

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.

When using S-Docs in batch mode, a user can 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.

All of this can be accomplished using the S-Docs Job object. This object can easily be integrated with Processes, APEX code, Flows, and more.

Alternatively, you have the option of using the legacy methods of using S-Docs with automation, workflow, and batch processing. These methods involve the REST API, which is leveraged to invoke document generation programmatically. This powerful feature means that documents can be created in the background (asynchronously) without any user involvement whenever defined criteria are met.

However, S-Docs Jobs can accomplish anything that the legacy method with the REST API can. Thus, for users who haven’t used the legacy method yet, we recommend that you use S-Docs Jobs as your primary solution. The REST API methods we’ve included are intended as a reference only for users who have already implemented these methods. You can read about the S-Docs REST API here.

Automatic Document Generation with S-Docs Jobs (Recommended)

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, or other integrations. Rather than using S-Docs Jobs with workflows, 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 it's fields can be found in following list:

To automatically generate S-Docs with S-Docs Jobs, you will need to create an S-Docs Job record, specify the ID of the record you would like to generate these documents for, specify this record’s object API name (Opportunity, Account, etc.), specify the ID of the S-Docs templates you would like to use for document generation, and 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 you create an S-Docs Job in APEX code, Salesforce flows, etc., they are stored as S-Docs Jobs records. We will give a brief overview of these records. Navigate to the “S-Docs Jobs” tab. If it is not a default tab, click the All Tabs (+ icon) tab and find it on the following page.

jobs rest - 01


Click the All list view to see all of our Jobs records. In most (if not all) cases, we will not be creating Jobs records with the New SDoc Job button here; the records here should be created by your APEX triggers, Salesforce flows, etc. However, you can select all of the logs here and use the Delete Logs button to clean them out whenever you would like (though this may also be done programmatically).

jobs rest - 02
If you open a Job record, you will see 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.

jobs rest - 03
The documents the Job generated will also be included in the record. If you would like to view the files generated by a Job, you do not need to find that Job record. A related list for these documents will be automatically created on the page of the record you generated the documents for. 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 on that account record’s page like so:

jobs rest - 04
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 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, in 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:

Fields for our Use Case
SDOC__Start__cThis 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__cIf 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 HTML email template should use a merged field to send an email to an address associated with a given account. 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: This is the Object ID field, i.e. the ID of the record we are creating objects for.

SDOC__ObjAPIName__cThis is the API name of our objects. In our example, we’re creating this trigger for new accounts, so we store Account in this field.

SDOC__Doclist__cThis is the comma-delimited list of the IDs of the S-Docs templates 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, a033A00000FWmzh is the ID of our S-Doc template for a welcome letter PDF, and a0236000005b2dM is the ID of our S-Doc template for an HTML email. Thus, we will be using the following Doclist for our example use case Salesforce Process, APEX code, and Salesforce Flow:


To find the template ID’s for use in your Doclist field, go to the record page for each template.

jobs rest - 05
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.

jobs rest - 06
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.

Run the S-Doc Job under a specified user. If we wanted this S-Doc Job to be run as a specified user in any of the following implementations, we would also add the "Run as User" field (SDOC_RunAsUser__c). This field takes a string, specifically the username of the user we want this Job to be run as. For example, say we wanted our new account's welcome letter to be sent from joe@example.com, even if joe@example.com was not the user who created the account. To do this, we would add the "Run as User" field and enter joe@example.com.

Using the "Run as User" field requires setting a few things up in order to work without any preauthorization (as required by Salesforce). Click here to read about this setup.

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. We navigate to Setup > App Setup > Create > Workflow & Approvals > Process Builder and create a new Process. We click Add Object, choose Account, and start the process only when a record is created.

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

jobs rest - 08
Then we click Add Action and choose SDoc Job for our record type. We then fill in the fields as previously discussed in the Fields for our Use Case section above.

jobs rest - 09
Note that for the Object ID field, we set the type to “Reference” and looked up “Account ID;” this gives this field the value [Account].Id, so when this S-Doc Job runs for a newly created account, it will know that account's ID.

Additionally, if we wanted this S-Doc Job to be run as a different user, we would click Add Row and add the "Run as User" field. For "Value," we would enter the username of the user we want this Job to be run under.

jobs rest - 10
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 simple to use with APEX triggers. We simply create a Job Object in the APEX trigger, fill in its fields as previously discussed in the Fields for our Use Case section above, and insert each Job into our Salesforce database. In order to automatically generate and email a welcome letter whenever an account is created, we could use the following APEX trigger:

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.

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

This 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 Flow is as simple as using any other object with Salesforce Flow, so this is easy to accomplish.

In our flow, we would first create a Record Create for an account.

jobs rest - 11
In this Record Create window, we must create a new variable called “acct.” This will store the record ID of an account created by this Record Create. Make sure the “Data Type” field is set to “Text.”

jobs rest - 12
Then we create a Record Create for our S-Doc Job. We fill in the fields as previously discussed in the Fields for our Use Case section. We use the drop-down menu to select the global constant corresponding to “true” for our SDOC__Start__c field. For our SDOC__SendEmail__c field, we simply type in “1” (without quotes) in order to specify 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). For the SDOC__Oid__c field, i.e. the Object ID field, we use the {!acct} variable we created above. This variable stores the ID of the account record created when the “Record Create” that we made for an account executes. For SDOC_ObjApiName__c, we type in “Account” (without quotes) since the API name for account objects is “Account.” For SDOC__Doclist__c, we type in the Doclist we discussed in the previous Fields for our Use Case section.

jobs rest - 13

We then save the Record Create for our S-Doc Job and attach the Record Create for an account to the Record Create for an S-Doc Job. 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.

jobs rest - 14

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.