DocusignEnvelopeRequest: - Add authReleaseFormCopies InvocableVariable (Integer, optional, 1-3) DocusignCompositeEnvelopeBuilder: - Add MULTI_COPY_TEMPLATE_NAME constant (single place to update if the template is renamed; matched via LIKE '%...%' covering both languages) - Before building the document list, query for template IDs matching the multi-copy template name and append (copies-1) additional IDs so the envelope contains the correct number of distinct documents - Duplicate-safe label builder: appends '(Copy N)' suffix to keep document labels unique within the envelope - Build deduplicated displayNames list for email subject/body: collapses multi-copy entries to a single line with a '(N)' count suffix, e.g. 'Authorization to Release Information (3)' - Email body: each template's message text is included only once even when the same template ID appears multiple times (bodyIdsAdded guard) - Log and Status label use displayNames (deduplicated) not raw docNames |
||
|---|---|---|
| .. | ||
| .husky | ||
| config | ||
| docs | ||
| force-app/main/default | ||
| scripts | ||
| .forceignore | ||
| .gitignore | ||
| .prettierignore | ||
| .prettierrc | ||
| QUICK_START.md | ||
| README.md | ||
| deploy-to-dev-org.sh | ||
| deploy.sh | ||
| eslint.config.js | ||
| jest.config.js | ||
| package.json | ||
| sfdx-project.json | ||
README.md
Salesforce Composite Envelope Builder
Project Overview
A Salesforce solution for sending multiple Docusign templates in a single envelope using composite template functionality via the Docusign REST API.
Problem Statement
Current implementation requires 42+ pre-built Docusign templates for various combinations of 14 forms (English + Spanish). This approach is:
- Difficult to maintain
- Cannot handle all possible combinations
- Requires creating new templates for each scenario
Solution
Build custom Apex code to dynamically combine multiple single-form templates into one envelope at runtime, allowing users to select any combination of forms.
Key Features
- Dynamic Form Selection: Users select forms via Salesforce Screen Flow checkboxes
- Single Template Per Form: 28 templates total (14 forms × 2 languages)
- Composite Envelope API: Combines templates into one envelope via Docusign REST API
- Alphabetical Ordering: Forms presented and combined in alphabetical order by title
- Automatic Recipient Merge: Recipients/roles automatically merged across templates
- Salesforce Integration: Documents written back to initiating Salesforce record
Technical Architecture
Components
-
Salesforce Screen Flow (existing, minor modifications)
- Language selection
- Template display and selection (checkboxes)
- Calls Apex action with selected template IDs
-
Custom Apex Class (new)
DocusignCompositeEnvelopeBuilder- Invocable method for Flow integration- Constructs composite envelope JSON
- Makes Docusign REST API callout
- Returns envelope ID to Flow
-
Unit Tests (new)
- Test class with >75% code coverage
- Mock callouts for Docusign API
- Edge case handling
Technologies
- Salesforce Platform: Apex, Screen Flows, Lightning Web Components (potential future UI)
- Docusign REST API v2.1: Composite Templates endpoint
- VS Code + Salesforce Extensions: Development environment
Project Structure
salesforce-composite-envelope-builder/
├── docs/
│ ├── requirements.md # Detailed requirements
│ ├── design.md # Architecture and design decisions
│ ├── api-reference.md # Docusign API integration details
│ └── deployment-guide.md # Deployment and configuration
├── force-app/main/default/
│ ├── classes/
│ │ ├── DocusignCompositeEnvelopeBuilder.cls
│ │ ├── DocusignCompositeEnvelopeBuilder.cls-meta.xml
│ │ ├── DocusignCompositeEnvelopeBuilderTest.cls
│ │ ├── DocusignCompositeEnvelopeBuilderTest.cls-meta.xml
│ │ ├── DocusignCredentials.cls
│ │ └── DocusignCredentials.cls-meta.xml
│ └── flows/
│ └── Form_Selection_Flow.flow-meta.xml (example/reference)
├── scripts/
│ └── apex/
│ └── test-composite-envelope.apex # Manual testing script
└── README.md # This file
Getting Started
See docs/deployment-guide.md for setup instructions.
Documentation
- Requirements - Functional and technical requirements
- Design - Architecture, sequence diagrams, data flow
- API Reference - Docusign REST API integration details
- Deployment Guide - Installation and configuration
Timeline
- Phase 1: Requirements & Design Documentation ✅
- Phase 2: Apex Class Development
- Phase 3: Unit Tests & Code Coverage
- Phase 4: Flow Integration
- Phase 5: Testing & Deployment
License
Internal project for customer implementation.
Last Updated: February 23, 2026
Project Lead: Paul Huliganga
Status: In Development