DocGenToolkit class provides a comprehensive interface for Box Document Generation operations within the Salesforce managed package. This class handles document generation requests, template management, and batch processing for creating documents from templates.
Class signature
Constructor
DocGenToolkit()
Default constructor for creating a new instance of the DocGenToolkit.
Document generation methods
submitDocGenBatch
Submits a document generation batch request to Box.
| Parameter | Type | Description |
|---|---|---|
docGenRequest | DocGenRequest | The request object containing all necessary parameters for doc generation. |
DocGenResponse- The response containing batch information and status.
GenerateDocGenForRecords with template code
Generates documents for multiple records using a template by ID and template code.
| Parameter | Type | Description |
|---|---|---|
recordIds | List<String> | List of Salesforce record IDs to generate docs for. |
templateId | String | The ID of the DocGen_Template__c record. |
templateCode | String | The code identifier for the template. |
List<DocGenResponse>- List of responses for each document generation request.
GenerateDocGenForRecords
Generates documents for multiple records using a template by ID only.
| Parameter | Type | Description |
|---|---|---|
recordIds | List<String> | List of Salesforce record IDs to generate docs for. |
templateId | String | The ID of the DocGen_Template__c record. |
List<DocGenResponse>- List of responses for each document generation request.
GenerateDocGenForRecords with folder override
Generates documents for multiple records with an optional folder override.
| Parameter | Type | Description |
|---|---|---|
recordIds | List<String> | List of Salesforce record IDs to generate docs for. |
templateId | String | The ID of the DocGen_Template__c record. Can be null if templateCode is provided. |
templateCode | String | The code identifier for the template. Can be null if templateId is provided. |
folderIdOverride | String | Optional folder ID to override the default destination folder. |
List<DocGenResponse>- List of responses for each document generation request.
Utility methods
generateFileName
Generates a file name by replacing template variables with actual data values.
| Parameter | Type | Description |
|---|---|---|
fileName | String | The template file name containing variables in {{field.subfield}} format. |
data | Map<String, Object> | Map containing the data to substitute into the file name. |
String- The generated file name with variables replaced.
- Use
{{Object.Field}}syntax to reference Salesforce object fields. - Supports nested object references like
{{Account.Name}}.
Batch management methods
getDocGenBatch
Retrieves information about a document generation batch by its ID.
| Parameter | Type | Description |
|---|---|---|
batchId | String | The ID of the batch to retrieve info for. |
DocGenResponse- The response containing batch status and details.
getDocGenBatchByURL
Retrieves document generation batch information by URL endpoint.
| Parameter | Type | Description |
|---|---|---|
endpoint | String | The URL endpoint to retrieve batch information from. |
DocGenResponse- The response containing batch information.
Template management methods
createTemplate from file ID
Creates a template from a Box file by its ID.
| Parameter | Type | Description |
|---|---|---|
fileId | String | The Box file ID to mark as a template. |
DocGenTemplateResponse- The response containing template information.
createTemplate from request object
Creates a template from a Box file using a custom template request.
| Parameter | Type | Description |
|---|---|---|
templateRequest | DocGenTemplateRequest | The request object containing template configuration. |
DocGenTemplateResponse- The response containing template information.
deleteTemplate
Deletes a template from Box by its file ID.
| Parameter | Type | Description |
|---|---|---|
fileId | String | The Box file ID of the template to delete. |
DocGenTemplateResponse- The response confirming the deletion.
getJobsForTemplate
Retrieves all jobs associated with a template record.
| Parameter | Type | Description |
|---|---|---|
templateRecordId | Id | The Salesforce ID of the DocGen_Template__c record. |
DocGenResponse- The response containing job information for the template.
Tag management methods
getTags
Retrieves available tags for a template by its ID.
| Parameter | Type | Description |
|---|---|---|
templateId | String | The Box template ID to get tags for. |
DocGenTagsResponse- The response containing available tags.
getTagsByURL
Retrieves available tags for a template by URL endpoint.
| Parameter | Type | Description |
|---|---|---|
endpoint | String | The URL endpoint to retrieve tags from. |
DocGenTagsResponse- The response containing available tags.
Common usage patterns
Basic document generation
Template creation and management
Batch monitoring
Error handling
When using theDocGenToolkit, handle potential errors as shown below:
Related classes
DocGenRequest- Request object for document generation.DocGenResponse- Response object containing batch information.DocGenTemplateRequest- Request object for template creation.DocGenTemplateResponse- Response object for template operations.DocGenTagsResponse- Response object for tag operations.DocGen_Template__c- Custom object for storing template metadata.
