S-Docs Software Development Kit (DocumentSDK)

Introduction

The DocumentSDK, also referred to as the S-Docs SDK is an essential tool for developers aiming to streamline document generation and email creation within their organizations. This SDK provides methods to simplify the process of creating documents and emails. It empowers developers to effortlessly integrate document generation and email creation features into their applications. The methods generateDoc and generateEmail facilitate the creation of documents and email content, providing developers with essential tools to enhance user experiences.

Explore the capabilities of the S-Docs SDK (DocumentSDK) and leverage its potential to streamline document-related tasks and elevate document management with ease within any org. Refer to the documentation below for more detailed information on implementation and usage.

The following is an overview of its capabilities:

DocumentSDK Methods

PDF Document Generation

Supported Contexts

The following contexts are supported:

  • Apex Invocable Class (that can be called from a Flow)
  • Apex Queueable
  • Apex Batch
  • @future Apex method
  • Visualforce Apex Controller (Custom and Controller extensions)
  • AuraEnabled Apex method
  • Apex class that supports an OmniScript
Note: Apex trigger context is not supported and will result in an Exception being thrown.
Use cases

With this SDK method you can generate documents from your own business processes as well as custom UI components. Some of the use cases that we anticipate to leverage this capability is as follows:

  • Generate a document in batch from an existing Apex Batch or Apex Queueable class
  • Generate a document from an existing UI component: Aura or Lightning Web Component
  • Generating a document from a custom Visualforce page
  • Generating a document from an OmniScript
Usage

In your apex class (Lightning Web component controller, Apex invocable, Queueable or Apex batch classes) you would invoke the above SDK method like below:

String jsonResp = SDOC.DocumentSDK.generateDoc('<templateId>','objectId');
Map<String,String> respAsObject = JSON.deserialize(jsonResp,
Map<String,String>.class)
Method Signature
generateDoc(Id templateId, Id objectId)
Parameters
templateId

(Type: Id): The ID of the template used for generating the document.

objectId

(Type: Id): The ID of the base record object.

Returns

Type:

String

Document information associated with the generated PDF in JSON format.

The return JSON will have the following structure:

{
"id": "<ID of SDOC__SDoc__c record created>",
"contentDocumentId": "Id of the corresponding ContentDocument record that was created",
"templateId": "<ID of Template passed in as the parameter>",
"recordId": "<ID of base record passed in as the parameter>",
"createdDate": "<Date of document created>",
"attachmentName":"<Name of file created>"
}
Limitations:
  • Currently only PDF and PDF-UPLOAD formats are supported.
  • You can only have 1 invocation of generateDoc per Apex transaction. I.e. if you invoke it multiple times in the same transaction you will get a LimitsException
  • If there is an error in generating the document, there is an Exception thrown that needs to be handled to introspect into the error details.
  • Runtime prompts based templates aren’t supported in the SDK.

HTML Email Generation

Supported Contexts

The following contexts are supported:

  • Apex Invocable Class (that can be called from a Flow)
  • Apex Queueable
  • Apex Batch
  • @future Apex method
  • Visualforce Apex Controller (Custom and Controller extensions)
  • AuraEnabled Apex method
  • Apex class that supports an OmniScript
Note: Apex trigger context is not supported and will result in an Exception being thrown.
Use cases

Since S-Docs email templates have the same ability to merge data fields from base objects, you can leverage this SDK to have richer email content that what the standard email templates support.

Usage

in your apex class (Lightning Web component controller, Apex invocable, Queueable or Apex batch classes) you would invoke the above SDK method like below:

String emailBody = SDOC.DocumentSDK.generateEmail('<templateId>','objectId');
Messaging.SingleEmailMessage
theEmail = new Messaging.SingleEmailMessage(); theEmail.setHtmlBody(emailBody);
...
..
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {semail});
Method Signature
generateEmail(Id templateId, Id objectId)
Parameters
templateId

(Type: Id): The ID of the template used for generating the email.

objectId

(Type: Id): The ID of the base record object.

Returns

Type:

String

String containing the email body in HTML format.

Info
The Generate Documents in Batch SDK method is available in the April '24 release and later.

Generate Documents in Batch SDK Method

Supported Contexts

The following contexts are supported:

  • Apex Invocable Class (that can be called from a Flow)
  • Apex Queueable
  • Apex Batch
  • @future Apex method
  • Visualforce Apex Controller (Custom and Controller extensions)
  • AuraEnabled Apex method
  • Apex class that supports an OmniScript
Note: Apex trigger context is not supported and will result in an Exception being thrown.
Use cases

Automate document generation across multiple records from multiple templates to streamline workflows that require batch processing.

Usage

In your apex class (Lightning Web component controller, Apex invocable, Queueable or Apex batch classes) you would invoke the above SDK method like below:

global static Id generateDocsInBatch(List<Id> baseRecordIds, Set<Id> templateIds, Integer batchSize) {
GenerateBatch batchInstance = new GenerateBatch(baseRecordIds, templateIds);
return Database.executeBatch(batchInstance, (batchSize == null ? 5 : batchSize));
Method Signature
generateDocsInBatch(baseRecords, templateIds, n)
Parameters
baseRecordIds

(Type: Id): The list of the records used for generating documents.

templateIds

(Type: Id): The set of IDs of templates to generate.

batchSize

(Type: Integer): The size of each batch in a job. (Default value is 5)

Returns

Type:

ID

The ID of the AsyncApexJob record returned by the system.

Was this helpful?