I have an envelope with 2 recipients and 5 documents. I'am using Docusign's Apex Toolkit to send the envelope for signatures. Recently I got a requirement to enforce signer visibility to show a set of documents in the envelope to Signer 1 and a set of documents in the envelope to Signer 2. I was able to achieve this with DocusignAPI's 'enforceSignerVisibility' property. I want to accomplish the same using Apex Toolkit (We HAVE to use the apex toolkit because we are automating the envelope send). Any help as to how to achieve this with Apex Toolkit will be a massive help
public static EnvelopeSendResponse sendEnvelope(final Id mySourceId) {
EnvelopeSendResponse response;
try {
// Capture customer details
Contact myCustomer = [SELECT Id, Name, Email FROM Contact WHERE Id =:mySourceId];
// Create an empty envelope
dfsle.Envelope myEnvelope = dfsle.EnvelopeService.getEmptyEnvelope
(new dfsle.Entity(mySourceId));
// Setup recipient data
dfsle.Recipient myRecipient = dfsle.Recipient.fromSource
(myCustomer.Name, myCustomer.Email, null, 'Signer 1', new dfsle.Entity(mySourceId));
// Add Recipient to the Envelope
myEnvelope = myEnvelope.withRecipients(new List<dfsle.Recipient> { myRecipient });
// myTemplateId contains the DocuSign Id of the DocuSign Template
dfsle.UUID myTemplateId1 = dfsle.UUID.parse('bf7ca600-XXXX-XXXX-XXXX-06e7f3b9e8ce');
// Create a new document for the Envelope
dfsle.Document myDocument1 = dfsle.Document.fromTemplate(
myTemplateId1, // templateId in dfsle.UUID format
'myTemplate1'); // The name of the template
// myTemplateId contains the DocuSign Id of the DocuSign Template
dfsle.UUID myTemplateId2 = dfsle.UUID.parse('bf7ca600-XXXX-XXXX-XXXX-XXXXXXX');
// Create a new document for the Envelope
dfsle.Document myDocument2 = dfsle.Document.fromTemplate(
myTemplateId2, // templateId in dfsle.UUID format
'myTemplate2'); // The name of the template
dfsle.UUID myTemplateId3 = dfsle.UUID.parse('bf7ca600-XXXX-XXXX-XXXX-XXXXXXX');
dfsle.Document myDocument3 = dfsle.Document.fromTemplate(
myTemplateId3, // templateId in dfsle.UUID format
'myTemplate3'); // The name of the template
dfsle.UUID myTemplateId4 = dfsle.UUID.parse('bf7ca600-XXXX-XXXX-XXXX-XXXXXXX');
dfsle.Document myDocument4 = dfsle.Document.fromTemplate(
myTemplateId4, // templateId in dfsle.UUID format
'myTemplate4'); // The name of the template
dfsle.UUID myTemplateId5 = dfsle.UUID.parse('bf7ca600-XXXX-XXXX-XXXX-XXXXXXX');
dfsle.Document myDocument5 = dfsle.Document.fromTemplate(
myTemplateId5, // templateId in dfsle.UUID format
'myTemplate5'); // The name of the template
// Add document to the Envelope
myEnvelope = myEnvelope.withDocuments(new List<dfsle.Document> { myDocument, myDocument2, myDocument3 , myDocument4 , myDocument5 });
// Send the envelope
myEnvelope = dfsle.EnvelopeService.sendEnvelope(
myEnvelope, // The envelope to send
true); // Send now?
response = new EnvelopeSendResponse('Envelope sent successfully', true);
}
catch(Exception ex) {
response = new EnvelopeSendResponse(ex.getMessage(), false);
}
return response;
}
This setting in the admin section ("Setting" from Docusign web app) controls document visibility. If you have the same requirements for all envelopes sent from this account, you can do this without having to specify doc visibility by just tagging the documents the way you want. So, say you have signers A, B, and documents 1, 2, if you only place a tag for signer A on doc 1 and signer B on doc 2 - then signer A will only see doc 1 and signer B will only see doc 2 without any changes in your apex code! To do that just change this drop-down to the appropriate option based on your needs (if your signers are members of your account, or not etc)
Note: At this time, the Apex toolkit does not yet have support for the excludedDocuments
property of the envelope.