WelisaWelisa DocGen
v1.1.0 welisa.com

Apex API#

Call Welisa DocGen from your own Apex — triggers, scheduled jobs, service classes, Lightning components. welisa.DocGenService is the global, subscriber-callable API. The package's controller classes (DocGenController, DocGenBulkController) are its own UI endpoints and are not callable from subscriber code; automate through DocGenService or the Flow actions.

Note

The package installs in the welisa namespace. From subscriber code: Apex welisa.DocGenService.generateDocument(…), Flow actions appear with the package label, and merge tags in templates use field API names without any prefix.

Backwards compatibility: the methods below are stable global entry points. New optional overloads may be added; existing signatures are not removed without a major version and a deprecation notice.

welisa.DocGenService — synchronous generation#

MethodReturnsPurpose
generateDocument(Id templateId, Id recordId)Id (ContentDocumentId)Generates, saves as a File on the record, returns the new ContentDocumentId. Uses the template's default output format.
generateDocument(Id templateId, Id recordId, String outputFormatOverride)IdSame, with 'PDF' / 'Word' / 'PowerPoint' / 'HTML' override. Throws on a locked template or an incompatible combination.
generatePdfBlob(Id templateId, Id recordId)Map<String,Object> (blob, title)Renders a PDF in memory without saving — to e-mail, attach elsewhere, or POST to another system.
generateDocumentFromData(Id templateId, Id recordId, Map<String,Object> preloadedRecordData)IdAs generateDocument, but skips the per-record query and uses the supplied map. For custom bulk loops.
generatePdfBlobFromData(Id templateId, Map<String,Object> dataMap)Map<String,Object> (blob, title)Renders a PDF straight from a caller-built data map — no SOQL, no record Id.
generateAndSaveFromData(Id templateId, Id attachmentRecordId, Map<String,Object> dataMap, String outputFormatOverride)Id (ContentDocumentId)As above, and saves the file linked to attachmentRecordId.
// Trigger PDF generation from an approval process
Id contentDocId = welisa.DocGenService.generateDocument(
    'a0zXXXXXXXXXXXXX',   // template Id
    accountId,            // record Id
    'PDF'                 // force PDF regardless of the template's default
);

// Template Id from a Custom Label, so it deploys cleanly
Id invoicePdf = welisa.DocGenService.generateDocument(System.Label.Invoice_Template_Id, invoiceId);

// Render in memory and e-mail without ever creating a File
Map<String, Object> result = welisa.DocGenService.generatePdfBlob(templateId, oppId);
Blob pdf = (Blob) result.get('blob');
String title = (String) result.get('title');

Exceptions. All methods throw welisa.DocGenException on validation failures (locked output format, missing template, PowerPoint → PDF, null data map). Catch it by name: catch (welisa.DocGenException e) { … }.

Sharing and field-level security. DocGenService runs with sharing — record access is enforced for the calling user. Field-level security is not re-checked inside the merge engine; a user with row access but restricted FLS on a referenced field still sees that value in the document. The …FromData overloads bypass the package's SOQL boundary entirely: the calling code is responsible for CRUD/FLS on the values it puts in the map. Gate them in your own code if you expose them to lower-privilege actors.

Flow actions from Apex#

Every invocable action can be called from Apex with Invocable.Action.createCustomAction(…). Full input/output signatures:

ActionClassInputsOutputs
Generate DocumentDocGenFlowActiontemplateId or templateApiName, recordId, saveToRecord, documentTitle, outputFormatOverride, jsonDatacontentDocumentId, contentVersionId, success, errorMessage
Generate Bulk DocumentsDocGenBulkFlowActiontemplateId, queryCondition, recordIds, jobLabel, combinedPdfOnly, keepIndividualFiles, batchSize, sort order, duplex paddingjobId, success, errorMessage
Generate Document (Auto Giant Query)DocGenGiantQueryFlowActiontemplateId, recordId, saveToRecordcontentDocumentId + contentVersionId (small) or jobId (large), isGiantQuery, success, errorMessage
Welisa: Create Signature RequestDocGenSignatureFlowActiontemplateId or templateApiName, relatedRecordId, signerRecords (List<DocGenSigner>: name, email, role, contactId), signingOrder, documentTitleFormat, emailMessage, emailSubject, sendEmails, requireEmailVerification, prefillSignerEmail, expirationDayssuccess, signatureRequestId, signerUrls, signerNames, signerEmails, signerRoles, emailStatus, errorMessage
Welisa: Send for SignatureSignatureFlowActiontemplateId / templateApiName, relatedRecordId, documentContentVersionId (external providers), signers, signingOrder, emailSubject, emailMessage, sendEmails, asyncsuccess, envelopeId, externalId, signerUrls, queued, errorMessage
Welisa: Write Back Signer Form FieldsDocGenFieldWritebackServicerequestId—
Validate Signature TokenDocGenSignatureValidatortokenisValid, errorMessage, signerName, documentTitle, documentUrl
Submit Signed Signature (legacy requests only)DocGenSignatureSubmittertoken, signatureDataisSuccess, errorMessage
Finalize Signature Image (legacy requests only)DocGenSignatureFinalizertoken, base64Image—

The old signers (List<Signer>) input on Create Signature Request is a deprecated inner type Flow cannot populate — always use signerRecords (List<DocGenSigner>). A Flow Apex-Defined variable requires a top-level global class with @AuraEnabled members and a global no-argument constructor, which DocGenSigner provides.

welisa.DocGenDataProvider — custom data source#

Implement this interface to feed a template from an external API, computed values or cross-object aggregations, then bind the template to the class (Data Source → Apex Class). The map's keys match the merge tags; nested maps become parent-lookup tags, lists of maps become loops.

global interface welisa.DocGenDataProvider {
    Map<String, Object> getData(Id recordId);
    List<String> getFieldNames();
}

A complete example and the binding steps are on the Query configuration page.

welisa.DocGenAiProvider — your own AI model#

Implement isAvailable(), getName() and generateHtml(String prompt) to let the designer generate and revise HTML templates through a model your org has access to; register the class in Welisa Settings → AI Provider Class. A provider must not make HTTP callouts from inside generation. Details: Templates.

Objects you may query#

All package objects are readable through the permission sets. The ones automation most often touches, with their welisa__ prefix:

ObjectUse
welisa__DocGen_Template__cTemplates — welisa__API_Name__c, welisa__Is_Active__c, welisa__Base_Object_API__c
welisa__DocGen_Template_Version__cVersions — welisa__Is_Active__c, welisa__Type__c, welisa__Pre_Decomposition_Status__c
welisa__DocGen_Job__cBulk and large-dataset jobs — welisa__Status__c, counts, merged-PDF file Id
welisa__DocGen_Signature_Request__c, welisa__DocGen_Signer__c, welisa__DocGen_Signature_Audit__cSignature requests, signers (each with their token and status), the immutable audit trail
welisa__Envelope__cOne row per send through the signature seam, whatever the provider
welisa__DocGen_Error_Log__cErrors captured during generation, bulk jobs and signing
welisa__DocGen_Settings__c (custom setting)Org configuration: site URL, sender address, verification defaults, AI provider