Salesforce Document Generation Guide

1. Architecture & System Overview

The EDocGen Salesforce Managed Package simplifies document automation by eliminating custom multipart HTTP requests, polling mechanisms, and complex OAuth authentication flows[cite: 4].

Key Architecture Features:

  • Secure Authentication: Managed via Salesforce Named Credentials linked to your EDocGen backend[cite: 4].
  • Asynchronous Execution: Apex invocations spin off background processing to handle heavy document loads without hitting governor limits[cite: 4].
  • Multi-Format Engine: Supports dynamic generation of PDF, DOCX, and PPTX documents from unified templates[cite: 4].
  • Automated Linking: Output files are automatically saved to Salesforce ContentVersion / Files and attached directly to target record IDs[cite: 4].

2. Quick Setup Checklist

  1. Install Package: Deploy the EDocGen Managed Package (namespace: edocgen) into your Sandbox or Production org[cite: 4].
  2. Configure Named Credential & App Settings: In the EDocGen Configuration tab, set your Named Credential, Apex Success Callback, and notification email addresses[cite: 5].
    EDocGen Configuration Page
    Figure 1: EDocGen Configuration tab showing Named Credential and Callback setup[cite: 5].
  3. Update Connection Credentials: Edit the configuration whenever switching environments or updating Named Credentials[cite: 5].
    Updating Named Credential Configuration
    Figure 2: Updating the active Named Credential binding in Salesforce Admin settings[cite: 5].
Need detailed setup steps? See the step-by-step Post-Install Configuration Guide[cite: 4, 5].

3. UI Integration Strategies

EDocGen supports single-record generation actions, list view bulk processing, and Apex-driven automation[cite: 4].

Record Action

Single Record Page

Bind the edocgen:Templates Lightning Component to a custom Action button on any standard or custom object page layout[cite: 4].

List View

Bulk List Button

Add a standard List Button targeting the packaged Flow URL /flow/edocgen/EDocGen to process multiple selected records[cite: 4, 5].

Automation

Apex & Flow API

Trigger background generation logic via Apex code, Scheduled Jobs, or Salesforce Invocable Actions[cite: 4].

Setting Up Single Record Actions

To add a document generation button to a record page (e.g., Order or Opportunity):

  1. Go to Object Manager > [Object] > Buttons, Links, and Actions and click New Action.
  2. Select Lightning Component as the Action Type, choose edocgen:Templates, and assign a label like Generate Document[cite: 5].
  3. Add the new action to the Salesforce Mobile and Lightning Experience Actions section of your Page Layout.
  4. Users can now generate documents directly from the record action bar[cite: 5].
    Generate Document Action on Record Detail Page
    Figure 3: The active Generate Document button on a record page[cite: 5].
  5. Select your template from the dialog to generate the output file[cite: 5].
    Template Selection Dialog
    Figure 4: Template selection dialog on a record[cite: 5].

Setting Up Bulk List View Actions

To enable multi-record generation from list views:

  1. In Object Manager under Buttons, Links, and Actions, click New Button or Link.
  2. Set Display Type to List Button and target the packaged URL /flow/edocgen/EDocGen[cite: 5].
    Generate Documents List Button
    Figure 5: Generate Documents list button on a list view[cite: 5].
  3. Follow the guided flow to process batch outputs[cite: 5].
    Bulk Generation Flow
    Figure 6: Bulk generation flow initiated from a list view[cite: 5].

Output Attachment & Template Management

Manage your document templates and access generated files directly inside Salesforce[cite: 5]:

EDocGen Templates in Salesforce
Figure 7: EDocGen Templates management in Salesforce[cite: 5].
Generated Document Output in Salesforce Files
Figure 8: Example generated PDF or DOCX file linked under Files[cite: 5].

Common Implementation Targets

Object Domain Output Documents Recommended Pattern
Opportunity / Quote Proposals, Master Service Agreements Single Record Action (Lightning Component)[cite: 4]
Order / Account Invoices, Statements, Account Summaries Apex Trigger or Scheduled Batch Job[cite: 4]
Contact / Case Batch Letters, Work Order Summaries List View Bulk Action Flow[cite: 4]

4. Apex API Reference

Execute document generation programmatically from Apex using the global entry point method[cite: 4]:

edocgen.EdocGenDocumentGeneration.generateDocuments(wrapper)[cite: 4]

Example: Single & Bulk Code Invocation

// Initialize wrapper with target Template ID and Record IDs
List<Id> recordIds = new List<Id>{ '001XXXXXXXXXXXX', '001YYYYYYYYYYYY' };
Id templateId = 'a0BXXXXXXXXXXXX'; // edocgen__EDocGen_Templates__c ID

edocgen.EdocGenDocumentGeneration.DocumentGenerationWrapper wrapper =
    new edocgen.EdocGenDocumentGeneration.DocumentGenerationWrapper(
        templateId,            // EDocGen Template ID or Name String
        recordIds,             // Single or multiple Record IDs
        null,                  // Org-Wide Email Address ID (Optional)
        'BillingAddress',      // To Address field API path (Optional)
        'Contact.Email',       // CC field API path (Optional)
        null                   // BCC field API path (Optional)
    );

// Trigger generation asynchronously
edocgen.EdocGenDocumentGeneration.generateDocuments(wrapper);

For extensive signature options and parameter details, reference the full Apex Quickstart Guide[cite: 4].

5. Template Data Mapping

Templates are configured using familiar Office tags (e.g., {Account_Name}, {Total_Amount}) and synced to Salesforce via the EDocGen Templates (edocgen__EDocGen_Templates__c) object[cite: 4, 5].

  • Cross-Object Mapping: Traverses parent and child relationships configured within the template[cite: 4].
  • Automated Delivery: Configure post-generation email dispatching including dynamic subject, body, and recipient fields[cite: 4, 5].
  • Activity Tracking: Automatically records completed generation tasks under target Salesforce Activity Timelines[cite: 4, 5].

6. Callbacks & Failure Notifications

Asynchronous Success Callback

To handle post-generation workflows (such as updating record status fields), implement the edocgen.ConnectorToOrg.ConnectorInterface[cite: 4]:

global class EDocGen_SuccessCallBack implements edocgen.ConnectorToOrg.ConnectorInterface {
    global void handleDocumentGenerateSuccess(Map<String, String> generateSuccessMap) {
        // Retrieve JSON mapping: RecordId -> ContentVersionId
        String recordToContentMapJson = generateSuccessMap.get('recordIdWithContentVersionIdMap');
        
        // Execute post-generation business logic
        System.debug('Generation output details: ' + generateSuccessMap);
    }
}

Admin Email Alerts

Configure comma-separated admin email addresses in the EDocGen Configuration Tab to instantly receive notifications if document rendering or file upload failures occur[cite: 4, 5].

Related Developer Documentation