This integration automatically sends Docusign contracts when Salesforce opportunities are marked as "Closed Won". It listens to Salesforce change events in real-time and triggers contract creation based on configurable business rules.
Note: This integration uses OAuth2 authentication for the Salesforce event listener, which provides a more secure and modern authentication approach.
- Listens to Salesforce Opportunity change events and validates they meet business criteria (Closed Won stage, minimum deal value)
- Retrieves contact details based on configured signer role and selects the appropriate Docusign template
- Creates and sends Docusign envelope with pre-filled fields, configured signers, and CC recipients
- Updates Salesforce opportunity stage to track contract status
Before running this integration, you need:
- A Salesforce account with API access
- Change Data Capture enabled for the Opportunity object
- OAuth2 credentials:
- Client ID
- Client Secret
- Refresh Token
- Refresh URL
- Base URL (your Salesforce instance URL)
This integration uses OAuth2 refresh token authentication for both API calls and the event listener. Learn how to set up Salesforce OAuth.
- A Docusign account (demo or production)
- Contract templates created with named fields
- OAuth2 credentials:
- Account ID
- Client ID
- Client Secret
- Refresh Token
- Refresh URL
- Scopes Required:
signatureimpersonation
This integration uses the official ballerinax/docusign.dsesign connector with OAuth2 refresh token authentication for automatic token renewal. Learn how to get Docusign credentials.
Configurations are organized by vendor-specific records for better structure and maintainability.
Record type: SalesforceConfig
clientId- Your Salesforce OAuth2 client IDclientSecret- Your Salesforce OAuth2 client secretrefreshToken- Your Salesforce OAuth2 refresh tokenrefreshUrl- Salesforce OAuth2 token endpoint (default:https://login.salesforce.com/services/oauth2/token)baseUrl- Your Salesforce instance URL (default:https://login.salesforce.com)
Important - Channel Configuration:
- The service in
main.balis configured to listen to/data/ChangeEventsby default (captures all object changes) - To listen to a different channel, update the service declaration in
main.bal:- For Opportunity-only events:
service "/data/OpportunityChangeEvent" on salesforceListener - For custom channels:
service "/data/YourCustomChannel" on salesforceListener
- For Opportunity-only events:
- The channel must be enabled in your Salesforce org's Change Data Capture settings
Record type: DocusignConfig
accountId- Your Docusign account IDclientId- Your Docusign OAuth2 client ID (Integration Key)clientSecret- Your Docusign OAuth2 client secretrefreshToken- Your Docusign OAuth2 refresh tokenrefreshUrl- Docusign OAuth2 token endpoint (default:https://account-d.docusign.com/oauth/tokenfor demo,https://account.docusign.com/oauth/tokenfor production)baseUrl- Docusign API base URL (default:https://demo.docusign.net/restapifor demo,https://na1.docusign.net/restapifor production)
Record type: TemplateSettings
defaultTemplateId- REQUIRED - Default Docusign template ID to use (e.g., "a1b2c3d4-e5f6-7890-abcd-ef1234567890")- You can find your template ID in Docusign by going to Templates > Select your template > The ID is in the URL
- Example URL:
https://demo.docusign.net/templates/details/a1b2c3d4-e5f6-7890-abcd-ef1234567890
templateConfigs- Array of template configurations for different product/deal types (optional)templateId- Docusign template ID for this specific configurationproductType- Opportunity type to match (optional)dealType- Deal type to match (optional)expirationDays- Days until expiration reminder (optional)
Example Configuration:
[templateSettings]
defaultTemplateId = "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
[[templateSettings.templateConfigs]]
templateId = "template-for-enterprise"
productType = "Enterprise"
expirationDays = 7
[[templateSettings.templateConfigs]]
templateId = "template-for-standard"
productType = "Standard"
expirationDays = 3Record type: BusinessRulesConfig
minimumDealValue- Minimum opportunity amount to trigger contract (default: 0.0)signerRole- Contact role to use as signer (options: "Primary Contact", "Billing Contact", "Decision Maker", "Executive Sponsor")ccRecipients- Array of CC recipientsemail- Recipient email addressname- Recipient name
fieldMappings- Array of field mappings from Salesforce to DocusignopportunityField- Salesforce Opportunity field namedocusignField- Docusign template field label
contractSentStage- Opportunity stage to set after sending contract (default: "Contract Sent")expirationReminderDays- Default expiration reminder days (default: 3)
- Sign in to your WSO2 Integration Platform account.
- Create a new Integration to import this repository.
- Select the Technology as
WSO2 Integrator: BI. - Choose the Integration Type as
Event Handlerand click Create. - Once the build is successful, click Configure to Continue and set up the required environment variables:
Salesforce Configuration:
salesforceConfig.clientId- Your Salesforce OAuth2 client IDsalesforceConfig.clientSecret- Your Salesforce OAuth2 client secretsalesforceConfig.refreshToken- Your Salesforce OAuth2 refresh tokensalesforceConfig.refreshUrl- Default:https://login.salesforce.com/services/oauth2/tokensalesforceConfig.baseUrl- Your Salesforce instance URL
Docusign Configuration:
docusignConfig.accountId- Your Docusign account IDdocusignConfig.clientId- Your Docusign OAuth2 client ID (Integration Key)docusignConfig.clientSecret- Your Docusign OAuth2 client secretdocusignConfig.refreshToken- Your Docusign OAuth2 refresh tokendocusignConfig.refreshUrl- Default:https://account-d.docusign.com/oauth/token(demo) orhttps://account.docusign.com/oauth/token(production)docusignConfig.baseUrl- Default:https://demo.docusign.net/restapi(demo) orhttps://na1.docusign.net/restapi(production)
Template Configuration:
templateSettings.defaultTemplateId- REQUIRED - Your Docusign template ID (find it in Docusign Templates section)
Business Rules (Optional):
businessRulesConfig.minimumDealValue- Minimum opportunity amount (default: 0.0)businessRulesConfig.signerRole- Contact role for signer (default: "Primary Contact")businessRulesConfig.contractSentStage- Stage name after sending (default: "Contract Sent")
- Click Deploy to deploy the integration.
- Once tested, you may promote the integration to production. Make sure to set the relevant environment variables in the production environment as well.
-
Authentication Errors:
- Verify Salesforce OAuth credentials (client ID, client secret, refresh token)
- Check OAuth token validity and refresh token
- Ensure Connected App permissions are correct (API, Refresh Token, Access and manage your data)
- Verify Docusign OAuth credentials (client ID, client secret, refresh token)
- Ensure Docusign refresh URL matches your environment (demo vs production)
-
Event Not Received:
- Verify Change Data Capture is enabled for Opportunity object in Salesforce
- Check channel name configuration matches Salesforce setup
- Review Salesforce event monitoring logs
- Verify OAuth credentials have proper permissions for event streaming
-
Docusign Errors:
- "Template ID is empty": Configure
defaultTemplateIdintemplateSettingsconfiguration - "Bad Request": Common causes:
- Template ID doesn't exist in your Docusign account
- Template role name mismatch (template must have a role named "Signer")
- Field labels in template don't match configured field mappings
- Invalid account ID
- Verify template ID exists in your Docusign account (Templates > Select template > Check URL)
- Check field names in template match configured field mappings
- Ensure access token has required scopes (signature, impersonation)
- Verify account ID is correct
- "Template ID is empty": Configure
-
Contact Not Found:
- Ensure opportunity has contacts with the configured role
- Check OpportunityContactRole records in Salesforce
- Verify at least one contact is marked as primary
-
Validation Errors:
- Check opportunity has required fields (Name, Amount)
- Verify contact has valid email address
- Ensure opportunity amount meets minimum threshold