Skip to navigation

EnvelopeService

View as Markdown
global with sharing class EnvelopeService
Description
Primary interface point for Docusign eSignature envelope management.

A basic flow would be:

 // Get an empty envelope definition to begin.
 Envelope e = dfsle.EnvelopeService.getEmptyEnvelope(new Entity(sourceId));
 // Send envelope and add source documents and recipients
 e = dfsle.EnvelopeService.sendEnvelope(e, false);
 // Get tagger URL (this must be in a future method or separate transaction to avoid a CalloutException)
 Url u = dfsle.EnvelopeService.getSenderViewUrl(e.docuSignId, new Url('https://my.return.url'));
 // Host the tagging session with the returned URL
 

Methods

@Deprecated global static Envelope createEnvelope( final Envelope envelope, final EnvelopeConfiguration envelopeConfiguration, final Boolean addFromSource )
Description
Creates a draft Docusign envelope record in Salesforce. This method does not send the envelope; to do so call dfsle.EnvelopeService.sendEnvelope.

This method does not make any API callouts. It involves a DML operation.

The caller must be assigned the DocuSign User permission set.

Returns
The newly-created envelope.
Parameters
envelope
final Envelope envelope
The envelope to create.
envelopeConfiguration
final EnvelopeConfiguration envelopeConfiguration
Deprecated - ignored.
addFromSource
final Boolean addFromSource
Load source documents and recipients.
See
dfsle.EnvelopeService.sendEnvelope for details on how to send the created envelope.
global static Id deleteEnvelope(final Id envelopeId)
Description
Deletes a draft Docusign envelope record from Salesforce. It does not delete draft or sent envelopes from Docusign. Those may be voided, but not deleted, via dfsle.StatusService.voidEnvelope.

This method does not make any API callouts. It involves a DML operation.

The caller must be the owner of the envelope.

Returns
The Salesforce source ID of the envelope. This can be used to redirect the user upon deletion.
Parameters
envelopeId
final Id envelopeId
The ID of the envelope to delete.
See
dfsle.StatusService.voidEnvelope for details on how to void a draft or sent envelope.
global static Envelope getEmptyEnvelope(final Entity source)
Description
Gets an empty envelope definition that can be subsequently completed, created, and sent. This envelope will be populated with appropriate defaults based on the current account settings and localizations.

This method does not make any API callouts or DML operations.

The caller must be assigned the DocuSign Sender permission set.

Returns
The empty envelope.
Parameters
source
final Entity source
The originating Salesforce entity for the envelope.
global static Envelope getEnvelope(final Id envelopeId)
Description
Retrieves a Docusign envelope by record ID.

This method does not make any API callouts or DML operations.

The caller must be the owner of the envelope.

Returns
The envelope matching the ID.
Parameters
envelopeId
final Id envelopeId
The ID of the envelope.
global static Url getSenderViewUrl(final UUID docuSignId, final Url returnUrl)
Description
Retrieves a sender view URL. This will return a one-time use Docusign tagger URL if called right after an envelope is created in the draft state.

When redirected back to the supplied returnUrl, Docusign appends an event parameter to the query string. Possible values include:

  • sent: The envelope was sent from the tagger. It may be appropriate to initiate signing at this point assuming the first signer or host is the current user.
  • save: The envelope was saved as a draft in Docusign.
  • cancel: The draft was canceled. Delete the envelope via the dfsle.EnvelopeService.deleteEnvelope method.
  • error: An error was encountered.

This method involves an API callout with no DML operations.

The caller must be the owner of the envelope.

Returns
The sender view URL.
Parameters
docuSignId
final UUID docuSignId
The Docusign envelope ID.
returnUrl
final Url returnUrl
The URL to redirect to once the sender action is complete.
global static Envelope retryEnvelope(final UUID transactionId, final Boolean sendNow)
Description
Retries sending a Docusign envelope by transaction ID. The envelope will not be resent if it was already sent successfully. This can be called when the status of the envelope is indeterminate, for example when the send operation times-out.

If the envelope cannot be located by transaction ID, an dfsle.APIException will be thrown with error code dfsle.APIErrorCode.NOT_FOUND

This method should be isolated on its own transaction as it involves an API callout followed by a DML operation.

If previously created, the caller must be the owner of the envelope. Otherwise the caller must be assigned the DocuSign Sender permission set.

Returns
The sent envelope.
Parameters
transactionId
final UUID transactionId
The transaction ID associated with the envelope. Must be non-empty.
sendNow
final Boolean sendNow
Whether to send immediately or save as a draft in Docusign.
global static List<Envelope> saveSentEnvelopes(final List<Envelope> envelopes)
Description
Completes a transaction initiated by dfsle.EnvelopeService.sendEnvelopes. This will create envelope and status records for each sent envelope.

Each envelope must have valid docuSignId and sent properties and an empty error property, otherwise an exception will be thrown and no envelopes will be saved. Any invalid envelopes should be filtered out prior to calling this method.

This method involves DML operations. It does not make any API callouts.

The caller must be assigned the DocuSign Administrator, DocuSign User, or DocuSign Sender permission set.

Returns
The sent envelopes with updated record IDs.
Parameters
envelopes
final List<Envelope> envelopes
The sent envelopes.
See
dfsle.EnvelopeService.sendEnvelopes to initiate the transaction.
global static Envelope sendEnvelope(final Envelope envelope, final Boolean sendNow)
Description
Sends an envelope to Docusign. This will also create the envelope record in Salesforce if necessary.

This method should be isolated on its own transaction as it involves an API callout followed by a DML operation.

If previously created, the caller must be the owner of the envelope. Otherwise the caller must be assigned the DocuSign Sender permission set.

Returns
The sent envelope.
Parameters
envelope
final Envelope envelope
The envelope to send.
sendNow
final Boolean sendNow
Whether to send immediately or save as a draft in Docusign.
global static List<Envelope> sendEnvelopes(final List<Envelope> envelopes)
Description
Immediately sends one or more Docusign envelopes.

This method involves web service callouts to Docusign, but no subsequent DML. It is intended for scenarios where multiple envelopes are sent in a single transaction or whenever else DML should be deferred. At the end of the transaction, dfsle.EnvelopeService.saveSentEnvelopes should be called. Otherwise the associated envelope and status records will not be created.

This call is limited to 99 envelopes at a time, and subject to hourly API and Salesforce Governor limits.

Every envelope must be valid or else a ValidationException will be thrown and no envelopes will be sent. If all envelopes pass validation, any API error for an envelope will be logged on the error property. Only successfully sent ones may be saved with dfsle.EnvelopeService.saveSentEnvelopes.

The caller must be assigned the DocuSign Administrator, DocuSign User, or DocuSign Sender permission set.

Returns
The sent envelope.
Parameters
envelopes
final List<Envelope> envelopes
The envelopes to send.
See
dfsle.EnvelopeService.saveSentEnvelopes to complete the transaction.
global static Envelope updateEnvelope(final Envelope envelope)
Description
Updates a draft envelope record in Salesforce, including documents and recipients. This is a more expensive call than dfsle.EnvelopeService.updateEnvelopeNotifications as it updates and recalculates child entries.

This method does not make any API callouts. It involves a DML operation.

The caller must be the owner of the envelope.

Returns
The updated envelope.
Parameters
envelope
final Envelope envelope
The envelope to update.