What is DocuSign?
- DocuSign is a product that provides the facility and functionality of a digital e-signature of the documents. DocuSign eSignature for Salesforce: This eSignature solution is available on AppExchange.
- DocuSign application gives the functionality to send, sign, and track Salesforce documents from anywhere, on any device.
- You can create document templates and documents to send to your users, and select multiple recipients based on your business process and if you want to customize it, we can customize the solution with Templates and Apex Toolkit via Apex Programming as well, assign signer order to sign the documents and then DocuSign take care of sending that document to those recipients in the order.
- Once the User’s signed documents we can customize the process with Document Writeback functionality, and we can Save completed documents back to the Salesforce respective Records.
Advantages of DocuSign?
- Via DocuSign process Since the sign process is digital, so it helps to sign Sales Contracts like MSA’s, SOW, quotes and Invoices, HR Documents, and any Approval process documents and it helps to sign 90% of Salesforce documents and contracts documents.
- DocuSign process gives the facility to send data from Salesforce like any custom or standard objects records details and send them to customers for signature with generated PDF, word documents, and PPT we can use multiple document formats for generating documents and after completion return to Salesforce records.
- Salesforce and DocuSign Integration helps your business process in Salesforce to send for e-signature with a single point and click.
- You can track where a documents like DocuSign App gives functionality in the AppExchange application itself to get real-time status on your envelopes/documents right from Salesforce. DocuSign eSignature Envelope Status gets your documents signed faster, so you can get more work done which helps in closing deals faster and does process fast.
- It helps Business End Users to perform processes in an easy way and convenience of document signing, and sharing with respective users anytime, anywhere, and on any device.
AppExchange URL for Salesforce DocuSign: DocuSign eSignature for Salesforce: The trusted eSignature solution
What is DocuSign Apex Toolkit?
- The Apex Toolkit is a collection of pre-defined Apex methods, classes, and utilities that provides a bunch of the DocuSign eSignature API functionality similar to an SDK, these methods, classes, and utilities help you to integrate DocuSign and Salesforce functionality into your Apex code and customize the e-Signature Process.
- We can customize and automate more using the DocuSign API functionality exposed by the Apex Toolkit. Automate remote signing using Flow Builder. Apex calls from a Lightning Web Component. If your business process and functionality are not achieved using OOTB process then if you want to build a customized process via Apex then in Salesforce implementation, we can use Apex to customize DocuSign eSignature for Salesforce, we recommend installing and using the Apex Toolkit. The Apex Toolkit is all classes and methods available from the DocuSign eSignature for Salesforce managed package i.e. currently available on the Salesforce AppExchange.
Apex Toolkit Services
- Send an envelope i.e., Document for e-Signature
- Bulk Send envelopes
- Send Multiple envelopes
- Send envelopes from trigger
- Send envelopes with Tabs.
Below are some Apex Toolkit classes which gives the functionality for each e-Signature Process:
- Account Service: Configure DocuSign account settings.
- Envelope Service: Create and send DocuSign envelopes.
- Document Service: Manage DocuSign envelope documents.
- Recipient Service: Manage DocuSign envelope recipients.
- Template Service: Manage DocuSign templates.
- Signing Service: Methods to support signing DocuSign envelopes.
- Status Service: We can manage the Envelope and Document Status i.e., view, correct, resend, and void.
- Bulk Send Service: Methods supporting bulk-sending envelopes to distribution lists.
For Demo Example:
- Refer the Basic screen flow designed to call Apex method from flow and Apex
- Below are the Apex Code which is calling from the Lightning Flow Button. Note: This is sample code according to the Business Process Apex Implementation varies.
public class DocuSignSendForeSignature { @InvocableMethod(label='Send For Signature') public static void eSignature(List<ID> ids) { List<Contract> contracts = [SELECT Id,Name,CompanySignedId,Company_Signed_By_Name__c,Company_Signed_By_Email__c,Customer_Signed_By_Name__c,Customer_Signed_By_Email__c FROM Contract WHERE Id in :ids]; sendForSignature(contracts[0]); } private static dfsle.Envelope createDocuSignEnvelopeAndAddRecipients(Contract contractRecord,List<dfsle.Recipient> signerRecipientList){ // Create an empty envelope. The initiating Salesforce entity. Use this myEnvelope for later sending dfsle.Envelope myEnvelope = dfsle.EnvelopeService.getEmptyEnvelope(new dfsle.Entity(contractRecord.Id)); // Add Recipient to the Envelope myEnvelope = myEnvelope.withRecipients(signerRecipientList); //Update Email properties //https://developers.docusign.com/docs/salesforce/apex-toolkit-reference/envelope.html EmailTemplate template = [SELECT Id, Name FROM EmailTemplate WHERE Name=: 'E-Signature Email Template' LIMIT 1]; Messaging.SingleEmailMessage mail = Messaging.renderStoredEmailTemplate(template.Id, contractRecord.CompanySignedId, contractRecord.Id); myEnvelope.withEmail(mail.getSubject(),mail.getPlainTextBody()); return myEnvelope; } private static List<dfsle.Recipient> buildSignerRecipientsList(Contract contractRecord){ List<dfsle.Recipient> signerRecipientList = new List<dfsle.Recipient>(); dfsle.Recipient myRecipient1 = dfsle.Recipient.fromSource(contractRecord.Company_Signed_By_Name__c, contractRecord.Company_Signed_By_Email__c, null, 'Signer 1', null); // Source object for the Recipient signerRecipientList.add(myRecipient1); dfsle.Recipient myRecipient2 = dfsle.Recipient.fromSource(contractRecord.Customer_Signed_By_Name__c, contractRecord.Customer_Signed_By_Email__c, null, 'Signer 2', null); // Source object for the Recipient signerRecipientList.add(myRecipient2); return signerRecipientList; } public static void sendForSignature(Contract contractRecord){ try{ List<dfsle.Recipient> signerRecipientList = buildSignerRecipientsList(contractRecord); dfsle.Envelope myEnvelope = createDocuSignEnvelopeAndAddRecipients(contractRecord,signerRecipientList); // Create a new document for the Envelope ContentVersion cv = getContractDocument(contractRecord.Id); dfsle.Document myDocument = dfsle.Document.fromFile(cv); // Add document to the Envelope myEnvelope = myEnvelope.withDocuments(new List<dfsle.Document> { myDocument }); // Send the envelope myEnvelope = dfsle.EnvelopeService.sendEnvelope(myEnvelope,true); }catch(Exception ex){ System.debug('Exception Send For Signature ='+ex.getMessage()+' : '+ex.getLineNumber()); } } public static ContentVersion getContractDocument(Id recordId){ Set<Id> docIdSet = new Set<Id>(); for(ContentDocumentLink docLink : [SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId=:recordId]){ docIdSet.add(docLink.ContentDocumentId); } List<ContentVersion> contentVersionList = new List<ContentVersion>(); if(!docIdSet.isEmpty()){ contentVersionList = [SELECT Id, Title,FileExtension,PathOnClient,FileType,OwnerId,ContentModifiedById,ContentModifiedBy.Name,ContentModifiedDate,ContentDocumentId FROM ContentVersion WHERE Title='Contract Document' AND IsLatest=true AND ContentDocumentId IN :docIdSet LIMIT 1]; } return contentVersionList.get(0); } }
References:
- Apex Toolkit Code Examples: https://github.com/docusign/code-examples-apex
- https://www.salesforce.com/video/7791755/
- https://developers.docusign.com/docs/salesforce/salesforce101/apex-toolkit/
- https://developers.docusign.com/docs/salesforce/apex-toolkit-reference/accountservice.html
- https://developers.docusign.com/docs/salesforce/apex-toolkit-reference/envelopeservice.html
- https://developers.docusign.com/docs/salesforce/apex-toolkit-reference/documentservice.html
- https://developers.docusign.com/docs/salesforce/apex-toolkit-reference/recipientservice.html
- https://developers.docusign.com/docs/salesforce/apex-toolkit-reference/templateservice.html
- https://developers.docusign.com/docs/salesforce/apex-toolkit-reference/signingservice.html
- https://developers.docusign.com/docs/salesforce/apex-toolkit-reference/statusservice.html
- https://developers.docusign.com/docs/salesforce/apex-toolkit-reference/bulksendservice.html