DocuSign eSignature Integration with Salesforce Lightning Flow
DocuSign is a company based in San Francisco, California that is considered by many to be the industry leader in electronic signature (e-signatures) technology. DocuSign’s software allows parties to sign contracts and other documents electronically rather than signing them with pen and paper. As a salesforce consultant in India, we use DocuSign to to sign contracts and other documents electronically. This eliminates the need for parties signing a contract to be physically present at the same location. The technology also provides important security protocols. Signed documents are uploaded and encrypted with a unique hash. The hash can later be compared to a document to ensure that no one has tampered with the contract or other uploaded document.
How to use DocuSign in flow with a custom button?
First of all, go to AppExchange and search for the DocuSign App.
Download and install it for all user
- DocuSign Configuration
-
: Go to the app through the Nine dots icon or App launcher and search for DocuSign App Launcher and Select It.
-
After selecting DocuSign, we will be able to see a Window like the below-given image and click “Sign up for free “.
- : After clicking on “Sign up for free”, the DocuSign Registration page will open, insert the correct information as per the requirement.
- After completing all steps a screen like the below given image is visible in the DocuSign Setup Tab.
- Go to ‘DocuSign Envelope Templates’ and upload the document which is needed to send for signature and click on the ‘Upload’ button.
- After uploading the document it will move to the next wizard for Recipients. There we need to Add Recipients to send Emails.
-
After adding Recipients it will move to the next step Merge fields. So, Add Merge Field to set the salesforce field in the document if needed.
-
In the ‘Place Fields’ step, we can customize the document just by dragging and drop of fields and signatures to the place we want.
- The ‘Options’ step will configure the templated by giving several options like Reminders that remind us to send emails on a particular date or time.
-
In the ‘Custom Button’ step a button is created when we check the page layout checkbox, but in our scenario, a flow is called from the custom button so we can’t use the ‘Custom Button’ wizard.
-
How to use DocuSign in the flow?
-
First of all, create one class and Inviolable Method for calling flow action, the sample code is here.
Code:-public class SendToReconstructions {
@InvocableMethod
public static List sendEnvelope(List record) {
Reconstruction__c mySource = record.get(0);
system.debug(‘mySource….’+mySource.Id);
sendEnvelopeInFuture(mySource.Id);
return Null;
}
@future(callout = true)
public static void sendEnvelopeInFuture(Id mySourceId) {
createAndSendEnvelope(mySourceId);
}
public static Id createAndSendEnvelope(Id mySourceId) {
dfsle.Envelope myEnvelope = dfsle.EnvelopeService.getEmptyEnvelope(
new dfsle.Entity(mySourceId)
);
Reconstruction__c rc = [SELECT id, contact__c FROM Reconstruction__c WHERE Id = :mySourceId LIMIT 1];
Contact myContact = [SELECT Name, Email FROM Contact WHERE Id = :rc.contact__c LIMIT 1];
dfsle.Tab mySignHereTab = new dfsle.SignHereTab()
.withScale(1) // 1/2 scale
.withRequired(true) // Signing is mandatory
.withPosition(new dfsle.Tab.Position(
1, // The document to use
1, // Page number on the document
500, // X position
500, // Y position
null, // Default width
null)); // Default height
// Create an anchor
dfsle.Tab.Anchor myAnchor = new dfsle.Tab.Anchor(‘Acknowledgement’);
// Create an Initial Here tab
dfsle.Tab myInitialHereTab = new dfsle.InitialHereTab()
.withRequired(false) // Signing optional
.withAnchor(myAnchor);
dfsle.Recipient myRecipient = dfsle.Recipient.fromSource(
myContact.Name,
myContact.Email,
null,
‘Signer1’,
new dfsle.Entity(rc.contact__c)
)
.withTabs(new List { // Associate the tabs with this recipient
mySignHereTab,
myInitialHereTab
});
myEnvelope = myEnvelope.withRecipients(new List { myRecipient });
dfsle.UUID myTemplateId = dfsle.UUID.parse(‘438228d7-1c86-40c2-a37e-b7f855ee070d’);
dfsle.Document myDocument = dfsle.Document.fromTemplate(
myTemplateId,
‘Services Framework Agreement’ );
myEnvelope = myEnvelope.withDocuments(
new List { myDocument }
);
myEnvelope = dfsle.EnvelopeService.sendEnvelope(
myEnvelope,
true
);
return myEnvelope.Id;
}
} -
Now to create flow go to Setup > Flow > New Flow > Auto launched Flow. Get records from objects as per the need
- Create one Variable to store the record id, which gets from the custom button URL
-
Add a new element Apex Action and select the inviolable method class name and set the input value and select the variable name which was created in step 3 and click ‘Done’.
-
Click ‘save as’ and Active the flow. Now we need to create a custom button that is when the user clicks on the button, Auto launched Flow is called and it sends an email to the current record. So, go to object manager and select ‘Buttons, Links, And Actions’, and set property like the below image.
/flow/sendEmailToReconstruction?reconstructionId={!Reconstruction__c.Id}&retURL={!Reconstruction__c.Id}
- Now go to the page layout and set the custom button
- Now custom button is visible on the record page.