Server-Side Document Generation

Document Generation

       
         With Document Generation, you can generate contracts, proposals, quotes, reports, non-disclosure agreements, service agreements, and so on.

Client-side document generation requires a user interaction and generates documents using an OmniScript. Salesforce provides sample OmniScripts and Integration Procedures that you can use and customize to implement these capabilities.

Server-side document generation typically doesn’t require user interaction. Instead, a backend server processes requests to generate documents.

Let’s examine the differences between client-side and server-side document generation.

 

Client-Side Document Generation 

Server-Side Document Generation 

1

Execution happens in a web browser, using web browser resources.

Execution happens on the back end, using dedicated Salesforce compute resources.

2

It works best for smaller files.

It works best for large and rendering-heavy files.

3

It’s a synchronous process, which means that after you request the document generation, you wait until the document is ready. Only then can you generate more documents.

It’s an asynchronous process, which means you can generate multiple documents at the same time.

4

It requires user input. On the object record, the user selects an option to create a document. The generated document is attached in the Notes and Attachment section of the record.

It can be trigger-based, for example, when the record status changes. The generated document is attached in the Notes and Attachment section of the record.

Server-Side Document Generation

Server-Side document generation is available in both the OmniStudio Foundation and Salesforce Industries packages. Server-Side document generation is an asynchronous process that's built for large and rendering-heavy documents and for document generation in batches. The Server-Side document generation service is secure and scalable and is hosted on Salesforce Hyperforce. The generated document is stored in your Salesforce org, and is attached to the object for which it's generated.

Server Side Doc Gen Use Case :

  • Best for asynchronous use cases that include a polling mechanism.
  • Best for documents with lots of token processing, heavy tabulation, or more than 200 line items.
  • Best for generating large batches of documents.
  • Best for trigger-based document generation, such as generating documents based on a Case status change.
  • Supports DOCX and PPTX templates.
  • Doesn't include multi-language support.

Steps to configure documentation for Industries CPQ Package



Step 2: Enable Server-Side Document Generation Setting for the Salesforce Industries Package(Help Link)

To enable Server-Side document generation, configure the document generation setting:
  1. From Setup, click Custom Code, and then click Custom Settings.
  2. Next to Contract Management Configuration Setup, click Manage.
  3. Click Edit, and then type the IsServerSideDocGenEnabled setup value as true.
NOTE
If the IsServerSideDocGenEnabled setting isn't available, click New to add and then type the value as true.

Step 3: Tokens (Trailhead Module Link)

You can insert three types of tokens into a template: variable, repeating content, and condition evaluation.

 

Token Type

Token Notation

Description

1

Variable token

{{token_name}}

Displays the value of a variable that is passed into the template as a JSON element. The displayed value uses the formatting of the first curly brace. For example, if the first brace in the token is italicized, the text in the token is italicized as well.

2

Repeating content token


{{#token_name}}
{{/token_name}}
AND
{{^token_name}}
{{/token_name}}


Repeats a content section.
A token beginning with the pound sign (#) indicates that the section repeats as many times as the item occurs in the input JSON array.
A token beginning with the caret (^) shows what is displayed if the input JSON array is empty or doesn’t exist. In this case, the section is displayed only once.
The token itself isn’t displayed, and values don’t use the token text formatting.

3

Condition evaluation token


{{#IF_token_name}}
{{/IF_token_name}}
AND
{{^IF_token_name}}
{{/IF_token_name}}


Checks a Boolean condition to display a section once or not at all.
If the value of a token beginning with #IF_ is true, the section appears once. If the value is false, it doesn’t appear.
If the value of a token beginning with ^IF_ is true, the section doesn’t appear. If the value is false, it appears once.
The displayed values don’t use the token text formatting.



Document Template Designer

A document template defines the structure, content, and format of generated documents. Document Template Designer is a tool you use to create document templates in Salesforce.

You can create Microsoft Word or PowerPoint documents that contain formatted text, including tables, paragraphs, columns, and images, and use these documents as the basis for new templates.

You can populate your documents with data stored in Salesforce or data from external databases. Document Generation templates accept JSON data from any source

Step 4: Configure design template and upload docx file

Steps to configure template
  1. Upload the file to Document Template Designer.
  2. Specify the template metadata, such as name and type.
  3. Choose the DataRaptors required for data mapping and extraction.




 
public static void createDocumentGenerationProcessRequest(Opportunity opp, OpportunityLineItem oli) {
Try{
List<vlocity_cmt__DocumentTemplate__c> documentTemplate = [SELECT Id,Name FROM vlocity_cmt__DocumentTemplate__c where Name LIKE 'ScheduleATemplate' WITH SECURITY_ENFORCED LIMIT 1];
Date todayDate = System.today();
if(documentTemplate.size()>0){
Map<Id,Account> allAccountMap = new Map<Id,Account>([Select Id,Name,Company_Registration_Number__c,(Select Id,Name,mailingAddress,fax,phone from Contacts order by LastModifiedDate desc LIMIT 1) from Account where Id =:opp.AccountId]);
TokenDataWrapper tokenObj = new TokenDataWrapper();
tokenObj.todayDate = todayDate.format();
tokenObj.paymentTerm = opp.Payment_Term__c;
//contract start date
Date startDateObj = opp.Start_Date__c;
tokenObj.contractStartDate = startDateObj!=null?startDateObj.format():'';
// initialize the parameters
String methodName = 'generateDocumentWithTokenData';
Map<String, Object> inputMap = new Map<String, Object>();
Map<String, Object> outputMap = new Map<String, Object>();
Map<String, Object> optionsMap = new Map<String, Object>();
// setup input parameters for the method to be invoked
inputMap.put('objectId', opp.Id);
inputMap.put('templateId', documentTemplate[0].Id);
inputMap.put('outputFileFormat', 'docx/pptx');
inputMap.put('tokenDataMap', JSON.serialize(tokenObj));
// System.debug('inputMap: ' + inputMap);
// setup options parameters for the method to be invoked, if needed
optionsMap.put('title', 'scheduleADocument - '+oli.Name);
optionsMap.put('returnAsPdf', false);
// instantiate the generic api
vlocity_cmt.DocumentServiceGateway voi = new vlocity_cmt.DocumentServiceGateway();
// invoke the method
voi.invokeMethod(methodName, inputMap, outputMap, optionsMap);
// display result
System.debug('success: ' + success);
System.debug('outputMap: ' + JSON.serialize(outputMap));
}
}catch(Exception e){
System.debug(e.getMessage());
}
}

SERVER-SIDE DOCUMENTATION LIMITATIONS

  • Content Version daily limit: The generated documents are stored in Salesforce Content. Each org type has a daily limit (per 24 hours) on how many .docx and .pdf documents can be generated and stored. For more information, see Content Version Limit.
  • File Storage limit: The org’s file storage limit is calculated by a base allocation. It’s based on your Salesforce org edition plus a per-user allocation multiplied by the number of standard licensed users in the organization. For more information, see File Storage Limit.
  • Size limit: The size limit of server-side generated documents is two MB. You can submit up to 1000 requests per hour, per org.

Resources

https://trailhead.salesforce.com/content/learn/modules/foundation-document-generation/create-document-templates

https://help.salesforce.com/s/articleView?
id=ind.v_contracts_t_server_side_document_generation_in_clm_379986.htm&type=5

https://help.salesforce.com/s/articleView?id=ind.v_contracts_t_client_side_and_server_side_document_generation_in_clm_compared_380073.htm&type=5



Comments

Popular posts from this blog

Communicating between Independent LWC in Omniscript

Salesforce Best Features available

Efficient way to write apex code