How to send an envelope with tabs
This topic demonstrates how to add tabs to your envelope.
Prerequisites
- Install the Docusign eSignature for Salesforce managed package.
- Create a subdomain for your Salesforce organization by enabling “My Domain.”
- Select the Docusign Setup tab and complete the login step.
Required data
Running the code in this how-to requires this data:
Step 1. Define your class and method
Create the class and method that will contain the code in this example. You can skip this step if you are adding this code to an existing class.
Step 2. Create your envelope definition
Use the dfsle.EnvelopeService.getEmptyEnvelope method to create an empty envelope definition that will be subsequently completed, created, and sent. Specify the Salesforce source ID of the record in the dfsle.Entity parameter that is to be used as the source object for the envelope.
Step 3. Specify a document for the envelope
Create a new dfsle.Document and add it to the envelope. This example uses the dfsle.DocumentService.getDocuments method, passing in the ContentDocumentId of a document already stored in a Salesforce library. Then, it uses the Envelope’s dfsle.Envelope.withDocuments method to add the document to the envelope.
Step 4. Define the recipient tabs
Create one tab each of types Sign Here, Initial Here, Date Signed, and Text, and associate them with your document. These are just four of the many tab types supported by the Apex Toolkit. The Sign Here tab is placed in the document using Auto-place (anchor tagging).
Step 5. Specify the recipient for the envelope
Create a dfsle.Recipient object for each recipient of the envelope and add tabs using the withTabs method. In this example, the envelope will have one signer recipient. Once a recipient is created, use the withRecipients method to add it to the envelope.
Step 6. Send the envelope
Send the envelope using the dfsle.EnvelopeService.sendEnvelope method. The sendNow parameter is set to true to indicate that you want to send the envelope immediately. Setting the sendNow parameter to false will save the envelope as a draft. The Apex Toolkit does not support sending a draft envelope. To send a draft envelope, you will need to call the eSignature REST API outside of the Apex Toolkit.
Step 7. Get the status
Docusign administrators can track the status of Docusign envelopes after sending them to recipients by using the Apex Toolkit dfsle.StatusService.getStatus method. This method returns the current status of the envelope (Created, Deleted, Sent, Delivered, Signed, Completed, or Declined), the time and date of the most recent action on the envelope, and other information as a list of dfsle.Envelope.Status objects. This method is passed a set of Salesforce source records that are associated with envelopes and an integer specifying the maximum number of records that will be returned.
Getting envelope status is useful to ensure that the envelope operations you’ve already performed, such as sending, confirming delivery, signing, or completion, have been executed successfully and to detect new status changes for an envelope. You must be the sender of the envelopes to call the dfsle.StatusService.getStatus method.
Step 8. Execute your method
To execute your code, go to the Developer Console in Salesforce, open the Debug menu, then select Open Execute Anonymous Window. Type the accompanying code in the window and select Execute.
View the source code for this how-to on GitHub: Apex.
Next steps
- See all available Apex Toolkit How-to guides.
- Learn more about tabs and how to use them in your documents.
- Learn How to send an envelope.
- See How to perform unit testing to ensure that you have adequate code coverage.