Skip to content

DocuSign eSignature for Salesforce Essentials – How to generate Envelopes dynamically with Apex Toolkit

Intro
In this post, I wanted to show how to build a dynamic DocuSign Envelope using Apex Toolkit.
DocuSign has been around for a while but not everyone is aware of the recent enhancements to the way DocuSign is pre-integrated with Salesforce. They have recently released eSignature for Salesforce Essentials managed package that contains two main improvements namely:
  • Refreshed set of admin pages and wizards for Salesforce that covers most of the standard use cases and eliminates the need to configure custom links and buttons – the package generates everything for you based on your answers in the configuration wizard
  • Apex Toolkit is a library of useful services in Apex that allow you to take full control of the DocuSign integration without building any custom integration code. Apex Toolkit nicely abstracts DocuSign capabilities from the integration logic so that you just write your business logic and the Toolkit takes care of the rest. No REST or SOAP required.
In this post, I will show how to use Apex Toolkit to support more complex use cases as Apex Toolkit gives you virtually unlimited possibilities to automate business processes and make the DocuSign experience tailored to your needs.
Initial setup

To play with DocuSign I would recommend signing-up for free sandboxes on both Salesforce and DocuSign that can be done here for salesforce and here for DocuSign.

Once you have the sandboxes up and running the next thing is to beef up your salesforce org with DocuSign packages:

I personally do not necessarily like the idea of installing two packages to support similar features as this might not be the cleanest way of doing things. We will also end up with some duplications in the org (multiple Permission Sets, Multiple Quick Actions, multiple objects). Unfortunately, if you would like to use all the features from Salesforce UI this is the only way to go (for now at least) and this is what DocuSign recommends in their demos as well. DocuSign also presents the new Essentials package as something that can be added to the existing org and will not cause any problems. So in case you have an org that is using eSignature but you would like to start using Apex Toolkit Essentials installation is the way to go.
Our Use Case
That would be it for the intro now let’s focus on my Use Case. Let’s assume we have a Custom Multiselect Picklist field in Salesforce that drives documents that need to be sent to the customer for signature depending on the selected items. This might be e.g. add-on contracts on the device sold like extended warranty, extended support, financing, etc. The goal is to send one DocuSign Envelope with all relevant documents in one email to the Customer and relevant signers.
As this is not a standard Use Case we would need to use Apex Toolkit in order to acheive this functionality. DocuSign will take care of
  • generating the documents
  • populating custom fields based on the Salesforce Record data (Document Custom Fields)
  • Presenting Envelope Status on Record Page
  • Uploading individual documents once they are signed onto Salesforce Record.
The only customization that we need to do is to build a Quick Action – I am recommending Lightning Flow as it is the future of Salesforce automation and gives you good point-and-click space to perform business validations before calling Apex Class the will build the Envelope using Services exposed by Apex toolkit.
The sample code of the Class might look similar to this:
This is how easy it is to build dynamic Envelopes when the point-and-click tools are not enough to fulfil your requirements. The beauty of this solution is the only the Envelope generation is customized.
Resources: