To start work with document generator, System Administrator needs to create correct Template Configuration. There are two available types of configurations:

  1. Global Tokens Configuration
  2. Template Configuration

Global Tokens Configuration

Global configuration allows to add tokens, which can be reusable in different templates. Each change on such token will be reflected in all templates.

To define global configuration open Template Configuration tab and click ‘New’. Select ‘Global Tokens Configuration’ from available record types.

Under each global configuration Admin needs to define specific – names and values for each token.
Value for token can be taken from Object field value, or can be defined by User as simple text.

Global tokens are specified by object. One object type can have only one Global Token configuration. Deletion of global token is not possible, if at least one active template configuration use this token.
User can check, whether any of token is already used in existing Template Configurations, on related list named ‘Related Template Configurations’

Template Configuration

From available tabs, choose Template Configuration and click on New button. Select ‘Template Configuration’ from available record types.

Fill in appropriate fields and save the configuration.

Field NameRequiredField Description
Object Api NameYesSpecify base object for template configuration
Document TypeYesSpecify if generated document should be assigned to record as docx or pdf type
Attach AsYesSpecify if generated document should be assigned to record as a File or Attachment
Document NameNoDescribe document name. It can contains tokens to fill by data. It needs to be one of general token or one from defined in configuration (example ‘CV {{contactName}} – {{c.TODAY}}’)
DescriptionNoDescribe configuration details

When ‘Document Type’ is set to ‘.pdf’ , new checkbox appears called ‘Is PDF Protected’. This field allows to set password protection on generated file.
Password configuration is described in PDF Protection section.

After configuration has been created, System Administrator needs to upload previously created docx template. To do that click on ‘Upload Template’ button from Template Configuration page.

Based on docx document, system will create token configuration map. On this map System Administrator should match tokens to appropriate data.

Application gives three types of data source:

  1. Object – get data from exact object field
  2. Method – get data from defined method
  3. Global – get data from global tokens configuration
  4. Text – put defined text

Retrieve data from Object

From configuration picklist select ‘Object’ → find object field name

Retrieve data from method

To use that type of data source, System Admin should create class with TemplateApexDataProvider interface implementation. Interface includes two methods

  • getAvailableTokensWithLabels – method should define token names and labels which should be displayed on available picklist values
  • getDataSource(TemplateApexDataProviderContext context) – method should get data from database and assign it to appropriate tokens

After correct class will be created, it should be visible when ‘Method’ data source is selected.

Example data provider implemetation:

public with sharing class ContactApexDataProvider implements TemplateApexDataProvider{

	public Map<String, ApexDataProviderTokenLabelInfo> getAvailableTokensWithLabels(){
		Map<String, ApexDataProviderTokenLabelInfo> example = new Map<String, ApexDataProviderTokenLabelInfo>();
		example.put('account_name', new ApexDataProviderTokenLabelInfo('Account Name'));
		example.put('nr_empl', new ApexDataProviderTokenLabelInfo('Nr of Employees'));
		ApexDataProviderTokenLabelInfo table = new ApexDataProviderTokenLabelInfo('Contacts');
		table.addChild('table_first_name', 'First Name');
		table.addChild('table_last_name', 'Last Name');
		example.put('contacts', table);
		return example;
	}
	public Map<String, Object> getDataSource(TemplateApexDataProviderContext context){
		Account acc = [
				SELECT Id, Name, NumberOfEmployees,
				(SELECT FirstName, LastName FROM Contacts)
				FROM Account
				WHERE Id = :context.getRecordId()
		];
		Map<String, Object> example = new Map<String, Object>();
		example.put('account_name', acc.Name);
		example.put('nr_empl', acc.NumberOfEmployees);
		List<Map<String, String>> innerFields = new List<Map<String, String>>();

		for (Contact contact : acc.Contacts){
			Map<String, String> contactValues = new Map<String, String>();
			contactValues.put('table_first_name', contact.FirstName);
			contactValues.put('table_last_name', contact.LastName);
			innerFields.add(contactValues);
		}

		example.put('contacts', innerFields);
		return example;
	}
} 

Retrieve data from Global Tokens Configuration

From configuration picklist select ‘Global’ → find available global value.
To save user time for filling tokens, application allows to autopopulate values from global configuration. This process match tokens defined in document template with tokens defined in global configuration and set them automatically. To do that click on ‘Autopopulate tokens’ button.

Clone Templates

If there is need to use similar, or the same document in new Template, there is possibility to clone existing configuration.
On Template Configuration page click ‘Clone’ button. New record will be created with the same settings. What needs to be done, is to upload docx template, add new changes and activate template.

Limit selected records for tables

Records selected to tables can be limited by specified conditions. This functionality is available under each table recognized in template configuration, only for Object data source.
To add condition, find table token and click ‘Add conditions’ button

New section will appear, with conditions definition.

System Administrator needs to specify condition parameters.

Condition FieldAvailable options/operatorsField Description
Take action whenAll Conditions Are Met Any Condition Is MetCustom Logic Is MetSpecify when condition should be fired
Custom LogicAND / OR / NOT / ()Specify custom logic using given operators. Numbers define appropriate condition. Example 1 AND (2 OR 3)
Filter conditionField / Operator / ValueSpecify condition filter for chosen object Field

Save and activate

To make Template Configuration be available in generation process, it has to be activated. It can be done by clicking ‘Save and activate’ button. If template is not ready yet, and needs to be completed later, it can be saved as draft.