Document Insights

Automation - Custom Forms (Lazarus & Google Gemini)

🔧 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

sCustomFormRequestJSON

(String) – A JSON-formatted string containing input parameters used to generate a custom form. The JSON must include the following keys:

  • sDocumentId(Required) ID of the ContentDocument where the form will be attached.

  • sTemplateName(Required) Name of the custom form template to be used.

  • sPrimaryObject(Required) API name of the primary Salesforce object (e.g., Opportunity, Loan__c).

  • currentRecordId(Required) Contextual record ID where the request was made.

  • source(Required) Name of the custom form API to be used. Values - Lazarus, Google Gemini.


📥 Input JSON Format

The method expects a JSON string containing the following fields:

JSON
{   
  "sDocumentId": "069XXXXXXXXXXXX",   
  "currentRecordId": "006XXXXXXXXXXXX",   
  "sTemplateName": "Loan Summary Template",   
  "sPrimaryObject": "Opportunity",
  "source": "Google Gemini"
}

🧪 Required Keys & Validation

Key

Required

Description

sDocumentId

✅ Yes

ID of the ContentDocument that will hold the generated form.

sTemplateName

✅ Yes

Name of the custom form template to be used. Stored in Document Insight Template record.

sPrimaryObject

✅ Yes

API name of the Salesforce object (e.g., Opportunity, Loan__c) for which the form is to be generated.

currentRecordId

✅ Yes

ID of the current record where the form request originated.

source

✅ Yes

Name of the custom form API to be used. Values - Lazarus, Google Gemini.


🔁 Automation Workflow

  1. Deserialize Input

    • Converts the input JSON into a map of keys and values using JSON.deserializeUntyped.

  2. Field Extraction & Validation

    • Extracts required keys: sDocumentId, sTemplateName, sPrimaryObject, currentRecordId and source

    • Validates that the required values are not null or blank.

    • If any required field is missing or blank, throws InvalidParametersException with a detailed error message.

  3. Wrapper Construction

    • Constructs a GenericFormWrapper instance and populates it with the validated input.

  4. Queueable Execution

    • Enqueues QueueableCallCustomFormService with a list of wrappers to handle asynchronous form generation and processing.


✅ Expected Outcome

  • A Custom Form Parsing request is added to the queue.

  • The QueueableCallCustomFormService job takes over, generating the appropriate custom form using the specified template and object context.


⚠️ Error Handling

Scenario

Action

Missing sDocumentId

Adds "Document Id is Null" to the error message

Missing sTemplateName

Adds "Template Name is Null" to the error message

Missing sPrimaryObject

Adds "Primary Object is Null" to the error message

Missing source

Adds "Source is Null" to the error message

Any of the above fail

Throws InvalidParametersException with full error message


🧬 Supporting Classes & Services

Class/Service

Description

GenericFormWrapper

Wrapper class to hold custom form parameters.

QueueableCallCustomFormService

Queueable job that handles actual form generation logic.

InvalidParametersException

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:

  • sDocumentId should be a valid ContentDocumentId.

  • currentRecordId is optional but useful for tracking or context.

  • sTemplateName must match an available form template in your system.

  • source must match either “Google Gemini” or “Lazarus”.

  • sPrimaryObject is the API name of the Salesforce object you're generating the form for (e.g., Opportunity, Loan__c, etc.).