Document Insights

Automation - Moneythumb & Ocrolus

🔧 Method Signature

global static void automateProcess(String parentRecordId, String applicationName, Map<String, List<Id>> mapSelectedDocs)

📌 Purpose

The automateProcess method is a global automation entry point in the Document Insights application that prepares and initiates PDF document conversion through Moneythumb or Ocrolus, based on the selected documents.

It validates the selected documents, constructs a standardized request payload, and calls the internal PDF Insight processing service to perform document parsing and analysis.


🧾 Parameters

Parameter

Description

parentRecordId

(String) – Salesforce ID of the parent record (e.g., Loan, Opportunity, Application) under which the documents are being processed.

applicationName

(String) – Name of the invoking application. Can be left empty as well.

mapSelectedDocs

(Map<String, List<Id>>) – A map of selected documents:

  • Key = DocumentType::Source (e.g., Bank::MoneyThumb)

  • Value = List of ContentDocumentIds to be processed.


⚙️ Supported Document Types per Vendor -

  • MoneyThumb - Bank Statements,Credit Card Statements,Plaid JSON

  • Ocrolus - Bank Statements, Credit Card Statements, Plaid JSON, Driving License, Passport, Passport Card, SSN, PayStubs, SSA-1099, IRS Form 1040 (2022), IRS Form W-2


🔁 Automation Workflow

1. Retrieve Valid Document Types

  • Fetches the list of allowed document types from custom metadata or configuration via ConfigurationService.getValidPDFType().

2. Input Validation

  • Validates:

    • parentRecordId is not blank.

    • mapSelectedDocs is not null or empty.

    • Each document type prefix (before ::) is among the valid types (e.g., Bank, CCard, Plaid).

  • If any validation fails, it throws an InvalidParametersException with a detailed error message.

3. Document Preparation

  • Iterates through the map entries.

  • For each document, parses:

    • DocumentType – extracted from the key before ::.

    • Source – extracted from the key after ::.

    • ContentDocumentId – each file/document Id in the list.

  • Constructs a list of SelectedDocumentWrapper objects with this information.

4. Service Invocation

  • Serializes the wrapper list into JSON.

  • Invokes PDFInsightRequestController.callPDFInsightService() with:

    • The parent record Id

    • The JSON payload of document metadata


✅ Expected Outcome

  • Valid documents are queued for processing via the Document Insights pipeline.

  • The target PDF processing service (Moneythumb or Ocrolus) is called internally based on the source metadata.

  • Status tracking and further processing are handled in downstream logic (outside this method).


⚠️ Error Handling

Scenario

Action

parentRecordId is blank

Adds error message: "Parent Record Id cannot be null."

mapSelectedDocs is empty/null

Adds error message: "At least one document is required to start the Document Convert Process."

Invalid DocumentType

Adds error message: "Invalid Document Type. Valid values: Bank, CCard, Plaid."

If any of the above fail

Throws InvalidParametersException with the combined error message


🧪 Example Input

Java
Map<String, List<Id>> selectedDocs = new Map<String, List<Id>>{'Bank::Moneythumb' => new List<Id>{'069XX0000001abc', '069XX0000001xyz'}};
AutomatePDFInsightProcess.automateProcess('006XX000000abcd', '', selectedDocs);

🗂️ Supporting Classes & Services

Component

Description

ConfigurationService.getValidPDFType()

Returns a delimited string of valid document types (e.g., "Bank,CCard,Plaid").

PDFInsightRequestController.SelectedDocumentWrapper

Wrapper class with fields: sDocumentType, sSource, sContentDocumentId.

PDFInsightRequestController.callPDFInsightService()

Performs the actual callout/logic to submit documents to Moneythumb/Ocrolus.

InvalidParametersException

Custom exception thrown on invalid inputs.