🔧 Method Signature
global static void automateCustomFormService(String sCustomFormRequestJSON)
📌 Purpose
The automateCustomFormService method is a global utility designed to automate the population and processing of custom form templates (e.g., PDFs or smart forms) in the Document Insights application.
This method parses an input JSON payload, validates the required fields, wraps the data in a GenericFormWrapper, and enqueues a Queueable job to generate the form based on a specific template.
It enables asynchronous form generation with dynamic mappings to different Salesforce objects.
🧾 Parameters
|
Parameter |
Description |
|---|---|
|
|
(String) – A JSON-formatted string containing input parameters used to generate a custom form. The JSON must include the following keys:
|
📥 Input JSON Format
The method expects a JSON string containing the following fields:
{
"sDocumentId": "069XXXXXXXXXXXX",
"currentRecordId": "006XXXXXXXXXXXX",
"sTemplateName": "Loan Summary Template",
"sPrimaryObject": "Opportunity",
"source": "Google Gemini"
}
🧪 Required Keys & Validation
|
Key |
Required |
Description |
|---|---|---|
|
|
✅ Yes |
ID of the ContentDocument that will hold the generated form. |
|
|
✅ Yes |
Name of the custom form template to be used. Stored in Document Insight Template record. |
|
|
✅ Yes |
API name of the Salesforce object (e.g., |
|
|
✅ Yes |
ID of the current record where the form request originated. |
|
|
✅ Yes |
Name of the custom form API to be used. Values - Lazarus, Google Gemini. |
🔁 Automation Workflow
-
Deserialize Input
-
Converts the input JSON into a map of keys and values using
JSON.deserializeUntyped.
-
-
Field Extraction & Validation
-
Extracts required keys:
sDocumentId,sTemplateName,sPrimaryObject,currentRecordIdandsource -
Validates that the required values are not null or blank.
-
If any required field is missing or blank, throws
InvalidParametersExceptionwith a detailed error message.
-
-
Wrapper Construction
-
Constructs a
GenericFormWrapperinstance and populates it with the validated input.
-
-
Queueable Execution
-
Enqueues
QueueableCallCustomFormServicewith a list of wrappers to handle asynchronous form generation and processing.
-
✅ Expected Outcome
-
A Custom Form Parsing request is added to the queue.
-
The
QueueableCallCustomFormServicejob takes over, generating the appropriate custom form using the specified template and object context.
⚠️ Error Handling
|
Scenario |
Action |
|---|---|
|
Missing |
Adds "Document Id is Null" to the error message |
|
Missing |
Adds "Template Name is Null" to the error message |
|
Missing |
Adds "Primary Object is Null" to the error message |
|
Missing |
Adds "Source is Null" to the error message |
|
Any of the above fail |
Throws |
🧬 Supporting Classes & Services
|
Class/Service |
Description |
|---|---|
|
|
Wrapper class to hold custom form parameters. |
|
|
Queueable job that handles actual form generation logic. |
|
|
Custom exception thrown for validation errors. |
✅ Apex Code Example
// Step 1: Create the input map
Map<String, Object> inputMap = new Map<String, Object>{
'sDocumentId' => '069AB0000001234',
'currentRecordId' => '006AB0000005678',
'sTemplateName' => 'Loan Summary Template',
'sPrimaryObject' => 'Opportunity',
'source' => 'Google Gemini'
};
// Step 2: Serialize the map to JSON
String jsonInput = JSON.serialize(inputMap);
// Step 3: Call the method with the JSON input
AutomatePDFInsightProcess.automateCustomFormService(jsonInput);
🔍 Notes:
-
sDocumentIdshould be a validContentDocumentId. -
currentRecordIdis optional but useful for tracking or context. -
sTemplateNamemust match an available form template in your system. -
sourcemust match either “Google Gemini” or “Lazarus”. -
sPrimaryObjectis the API name of the Salesforce object you're generating the form for (e.g.,Opportunity,Loan__c, etc.).