Overview
An organization using Docomotion can enable users without a Docomotion license to generate output in Silent mode through the Render API.
This is a site/organization option. To learn more about enabling this option contact Docomotion Support.
Note for System Administrators:
Render API and Docomotion Licensing
Each user who might trigger a silent generation of output using the Render API needs a Docomotion license. In organizations that purchased a Price Per Action (PPA) license, documents can be generated by users without a Docomotion license. However, users triggering silent generation need to be assigned Docomotion Generator permission set.
Note that no error message appears if a document is not generated due to lack of a license.
For more information contact the Docomotion Support team.
Render API
The render API enables generating output in Silent mode, without using the Generate Document screen.
The API includes the following methods:
- RenderCreateFile that generates output a document in a synchronous way
- RenderCreateFileAsync that generates output in an asynchronous way
- RenderBlob that generates output and creates a blob
- createLink creates a single signature (Signature_c) Object
- createLinks creates a list of signature (Signature_c) Objects
- insertLinks inserts the signatures into the generated output
- massGenerate generates output for a list of records in an asynchronous way
Those are global methods so can be called from anywhere in the Apex code of the organization on which Docomotion is installed. You only have to add the doco. namespace.
RenderCreateFile
Purpose
This method is used to generate output in a synchronous way.
Syntax
1. static String renderCreateFile(Integer formId, Id sobjectId, doco.RenderAPI.Mode aMode, doco.RenderAPI.Format format)
2. static String renderCreateFile(Integer formId, Id sobjectId, doco.RenderAPI.Mode aMode, doco.RenderAPI.Format format, Id whoId)
3. static String renderCreateFile(Integer formId, Id sobjectId, doco.RenderAPI.Mode aMode, doco.RenderAPI.Format format, String fileName)
4. static String renderCreateFile(Integer formId, Id sobjectId, doco.RenderAPI.Mode aMode, doco.RenderAPI.Format format, Id whoId, Boolean isActivatedVersion)
5. static String renderCreateFile(Integer formId, Id sobjectId, doco.RenderAPI.Mode aMode, doco.RenderAPI.Format format, Id whoId, String fileName)
6. static String renderCreateFile(Integer formId, Id sobjectId, doco.RenderAPI.Mode aMode, doco.RenderAPI.Format format, Id whoId, String fileName, Boolean isActivatedVersion)
7. static String renderCreateFile(Integer formId, Id sobjectId, doco.RenderAPI.Mode aMode, doco.RenderAPI.Format format, Id whoId, String fileName, Boolean isActivatedVersion, Id TemplateId)
8. static String renderCreateFile(Integer formId, Id sobjectId, doco.RenderAPI.Mode aMode, doco.RenderAPI.Format format, Id whoId, String fileName, Boolean isActivatedVersion, Id TemplateId, String subject)
9. static String renderCreateFile(Integer formId, Id sobjectId, doco.RenderAPI.Mode aMode, doco.RenderAPI.Format format, Id whoId, String fileName, Boolean isActivatedVersion, Id TemplateId, String subject, String addRecipient, String orgWideAddressId)
10. static String renderCreateFile(String formName, Id sobjectId, doco.RenderAPI.Mode aMode, doco.RenderAPI.Format format, Id whoId, String fileName, Boolean isActivatedVersion, Id TemplateId, String subject, String addRecipient, String orgWideAddressId)
Usage Notes
It can be used in an Apex class or in an Apex Trigger. When using it in an Apex Trigger, you need to call the method from a future method with the attribute callout=true.
Parameters
Name |
Type |
Description |
formId | Integer | The Docomotion Id of the Form. (not the SF Id). Either formId or formName is required. |
formName | String | The name of the Form. Either formId or formName is required. |
SobjectId | Id | (required) The SF Id of the Main Object of the Form from which we want to generate output |
aMode | Mode | (required) The output channel we want to use to generate the output. See ENUM Mode |
format | Format | (required) The format of the generated output. See ENUM Format |
whoId | Id | Email recipient. |
filename | string | Name of the generated output, if you want a name that is different from record name which is the default file name. |
isActivatedVersion |
boolean | Enables generating output from an activated version (not the published version). True – use the activated version False – use the published version |
TemplateId |
Id | Id of email template to be used for sending generated output. |
subject |
String | Subject line |
addRecipient |
String | Additional email recipient |
orgWideAddressId |
String | Id from Salesforce’s Organization-wide email addresses list. Enables using an email from Salesforce’s Organization-wide email addresses list as a sender of the email. |
Example
Generate output from a Form whose number is 596, with the Account with SF id: 001j000000IzfyB, as an Attachment and in a PDF format:
Call doco.RenderAPI.renderCreateFile(596,Id.valueOf(‘001j000000IzfyB’),doco.RenderAPI.Mode.ATTACHMENT,doco.RenderAPI.Format.PDF);
RenderCreateFileAsync
Purpose
This method is used to generate the output in an asynchronous way.
Syntax
1. static void renderCreateFileAsync(Integer formId, Id sobjectId, doco.RenderAPI.Mode aMode, doco.RenderAPI.Format format) 2. static void renderCreateFileAsync(Integer formId, Id sobjectId, doco.RenderAPI.Mode aMode, doco.RenderAPI.Format format, Id whoId) 3. static void renderCreateFileAsync(Integer formId, Id sobjectId, doco.RenderAPI.Mode aMode, doco.RenderAPI.Format format, String filename) 4. static void renderCreateFileAsync(Integer formId, Id sobjectId, doco.RenderAPI.Mode aMode, doco.RenderAPI.Format format, Id whoId, String filename)
Usage Notes
It can be used in an Apex class or in an Apex Trigger. You can use it in a trigger, without the future annotation. Because it’s an asynchronous method, you can catch the generated file back in the code.
Parameters
Name |
Type |
Description |
formId | Integer | The Docomotion Id of the Form. (not the SF Id). Either formId or formName is required. formName |
formName | String | The name of the Form. Either formId or formName is required. formName |
SobjectId | Id | (required) The SF Id of the Main Object of the Form from which we want to generate output |
aMode | Mode | (required) The output channel we want to use to generate the output. See ENUM Mode. |
format | Format | (required) The format of the generated output. See ENUM Format. |
whoId | Id | If the form includes an Interactive Collection, the SF Id of the contact or of the responder to provide feedback. This parameter is optional if the Form does not include an Interactive Collection. |
filename | string | Name of the generated output, if you want a name that is different from record name which is the default file name. |
EXAMPLES
Example 1: The following code can be used after Insert or after Update Trigger.
Running on one record (good for most instances):
Trigger generateDocumentSilentMode on Opportunity (after insert) { Opportunity opp = Trigger.new[0]; doco.RenderAPI.renderCreateFileAsync(4, opp.Id, doco.RenderAPI.Mode.Attachment, doco.RenderAPI.Format.PDF); } Example 2: Run on a Collection of records when importing opportunities from dataloader:
Trigger generateDocumentSilentMode on Opportunity (after insert) { for(Opportunity o : Trigger.New) { doco.RenderAPI.renderCreateFileAsync(4, opp.Id, doco.RenderAPI.Mode.Attachment, doco.RenderAPI.Format.PDF); } }
RenderBlob
Purpose
This method is used to create a BLOB (Binary Large OBject) with all the data relevant to the output generation file.
The BLOB can be used to download a file to the browser.
Syntax
1. static Blob renderBlob(Integer formId, Id sobjectId, doco.RenderAPI.Format format) 2. static Blob renderBlob(Integer formId, Id sobjectId, doco.RenderAPI.Format format, Id whoId)
Usage Notes
The method returns the BLOB of the output generation file. When using this method in a trigger you have to add the @future(callout=true) annotation.
Parameters
Name |
Type |
Description |
formId | Integer | The Docomotion ID of the Form. (not the SF Id). Either formId or formName is required. formName |
formName | String | The name of the Form. Either formId or formName is required. formName |
SobjectId | Id | (required) The SF ID of the Main Object of the Form from which we want to generate output |
format | Format | (required) The format of the generated output. See ENUM Format. |
whoId | Id | If the Form includes an Interactive Collection, the SF Id of the contact or of the responder to provide feedback. This parameter is optional if the Form does not include an Interactive Collection. |
EXAMPLE
The BLOB can be used to convert to pdf and attach to record.
Integer formId = 0;
Id sobjectId = Id.valueOf(‘00324000014zC8l’);
Blob newBlob = doco.RenderAPI.renderBlob(formId, sobjectId, doco.RenderAPI.Format.PDF);
System.debug(‘Blob value is: ‘ + newBlob);
Attachment attachmentPDF = new Attachment();
attachmentPdf.parentId = sobjectId;
attachmentPdf.name = ‘testName’ + ‘.pdf’;
attachmentPdf.body = newBlob;//.toPDF(newBlob.toString());
insert attachmentPDF;
createLink
Purpose
This method is used to create a Signature__c Object and optionally insert the data into the database.
Syntax
static doco__Signature__c createLink(Integer formId, Id sobjectId, Id whoId, Boolean chatter, Boolean toInsert) static doco__Signature__c createLink(Integer formId, Id sobjectId, Id whoId, Boolean chatter, Boolean toInsert, String fileName, Boolean isActivatedVersion, String addRecipient, String orgWideAddressId) static doco__Signature__c createLink(String formName, Id sobjectId, Id whoId, Boolean chatter, Boolean toInsert, String fileName, Boolean isActivatedVersion, String addRecipient, String orgWideAddressId)
When using the Docomotion4CPQ package replace doco__ with doco4cpq__.
Usage Notes
The method returns the Signature__c Object. You can use this Object to insert a signature into the generated output.
Parameters
Name |
Type |
Description |
formId | Integer | The Docomotion Id of the Form. (not the SF Id). Either formId or formName is required. |
formName | String | The name of the Form. Either formId or formName is required. |
SobjectId | Id | (required) The SF Id of the Main Object of the Form from which we want to generate output. |
whoId | Id | The SF Id of the contact or of the responder to provide feedback. |
chatter | Bool | Whether to create a chatter entry for the signature or not. |
toInsert | Bool | Whether to insert the data into the database or not. |
isActivatedVersion | Bool | Enables generating output from an activated version (not the published version). True – use the activated version False – use the published version |
addRecipient | String | Additional email recipient. |
orgWideAddressId | String | Whether to use an email from Salesfore’s Organization-wide Email Address list as a sender of the email output. |
createLinks
Purpose
This method is used to create a list of Signature__c Objects, and optionally insert the data into the database.
Syntax
static List createLinks(Id sobjectId, Map whoIdsMap, Boolean chatter, Boolean toInsert)
Usage Notes
The method returns the a list of Signature__c Objects. You can use these Objects to insert a signature into the generated output.
Parameters
Name |
Type |
Description |
SobjectId | Id | The SF Id of the Main Object of the Form from which we want to generate output |
whoIdsMap | Map<Integer, Id> | A map that maps formId (Integer) to whoId (SalesForce Id). |
chatter | Bool | Whether to create a chatter entry for the signature or not. |
toInsert | Bool | Whether to insert the data into the database or not. |
insertLinks
Purpose
This method is used to insert signatures, created by the createLink or createLinks methods (with toInsert = FALSE) or manually, into generated output.
Syntax
1. static Boolean insertLinks(List signatures)
Usage Notes
The method returns a boolean that indicates whether the insertion was successful or not.
Parameters
Name |
Type |
Description |
signatures | List | A list of Signature__c Objects. |
massGenerate
Purpose
This method is used to generate output for a list of records in an asynchronous way. For example if you want to send emails to the contacts of all selected Accounts, with a PDF attachment based on a Salesforce template.
Syntax
1. static void massGenerate(Integer formId, Set sobjectIds, doco.RenderAPI.Mode aMode, doco.RenderAPI.Format format, Boolean combine)
2. static void massGenerate(Integer formId, Set sobjectIds, doco.RenderAPI.Mode aMode, doco.RenderAPI.Format format, Boolean combine, Id TemplateId)
3. static void massGenerate(Integer formId, Set sobjectIds, doco.RenderAPI.Mode aMode, doco.RenderAPI.Format format, Boolean combine, String whoIdField)
4. static void massGenerate(Integer formId, Set sobjectIds, doco.RenderAPI.Mode aMode, doco.RenderAPI.Format format, Boolean combine, String whoIdField, Id templateId)
5. static void massGenerate(String formName, Set sobjectIds, doco.RenderAPI.Mode aMode, doco.RenderAPI.Format format, Boolean combine)
6. static void massGenerate(String formName, Set sobjectIds, doco.RenderAPI.Mode aMode, doco.RenderAPI.Format format, Boolean combine, Id TemplateId)
7. static void massGenerate(String formName, Set sobjectIds, doco.RenderAPI.Mode aMode, doco.RenderAPI.Format format, Boolean combine, String whoIdField)
8. static void massGenerate(String formName, Set sobjectIds, doco.RenderAPI.Mode aMode, doco.RenderAPI.Format format, Boolean combine, String whoIdField, Id templateId)
Parameters
Name |
Type |
Description |
formId | Integer | The Docomotion Id of the Form. (not the SF Id). Either formId or formName is required. |
formName | String | Name of the Form. Either formId or formName is required. |
SobjectIds | Set | (required) Set of the SF Ids of the Main Objects of the Form from which you want to generate output. |
aMode | Mode | (required)The output channel we want to use to generate the output. See ENUM Mode |
format | Format | (required) The format of the generated output. See ENUM Format. |
Combine | Boolean | Whether to combine outputs into one output or not. Note: Combing output is only supported for Mode.Document, and Format.PDF or Format.Html. |
whoIdField | string | String that contains the field name to be used as lookup for contact to which to send the email. |
TemplateId | Id | Id of email template to be used for sending generated output. |
Examples
See whoIdField usage in the following examples:
- Id to send the mail to the current Contact
- ReportsToId to send the mail to the ReportsTo of the current Contact
- ReportsTo.ReportsToId to send the mail to the ReportsTo of the ReportsTo of the current Contact.
Enum Format
static doco.RenderAPI.Format BMP
static doco.RenderAPI.Format DOCX
static doco.RenderAPI.Format GIF
static doco.RenderAPI.Format HTML
static doco.RenderAPI.Format HTML4S
static doco.RenderAPI.Format JPEG
static doco.RenderAPI.Format PDF
static doco.RenderAPI.Format PNG
static doco.RenderAPI.Format TIF
static doco.RenderAPI.Format TXT
Enum Mode
static doco.RenderAPI.Mode ATTACHMENT
static doco.RenderAPI.Mode CHATTER
static doco.RenderAPI.Mode DOCUMENT
static doco.RenderAPI.Mode DOWNLOAD
static doco.RenderAPI.Mode EMAIL
static doco.RenderAPI.Mode EMAILBODY
static doco.RenderAPI.Mode GOOGLE
static doco.RenderAPI.Mode LINK
Related Topics
GENERATING OUTPUT THROUGH THE GENERATE DOCUMENT BUTTON
GENERATING OUTPUT – SELECT RECIPIENT
ADDING SALESFORCE DOCUMENTS/FILES TO GENERATED OUTPUT
ADDING AN OUTPUT GENERATION ACTIVITY
HANDLING AND REVIEWING THE GENERATED OUTPUT
GENERATING OUTPUT VIA MOBILE APP.