Hi, I have created a Docusign Envelope Template (dfsle__EnvelopeConfiguration__c) with name “Opportunity Document”. I also used Docusign Salesforce Apex Toolkit to send the Email and adjust the email subject and email message dynamically. However, the email subject is not being overwritten by the code.
Relevant Apex Code:
Id mySourceId = opportunityId_i; // Opportunity ID
// Create an empty envelope.
dfsle.Envelope myEnvelope = dfsle.EnvelopeService.getEmptyEnvelope(
new dfsle.Entity(mySourceId));
// Use a Salesforce Contact ID as a Recipient
Contact myContact = opportunityIdToContactIdMap.get(opportunityId_i);
// Use the Recipient.fromSource method to create the Recipient
dfsle.Recipient myRecipient = dfsle.Recipient.fromSource(
myContact.Name, // Recipient name
myContact.Email, // Recipient email
null, //Optional phone number
'Signer', //Role Name. Specify the exact role name from template
new dfsle.Entity(myContact.Id));
// Add Recipient to the Envelope
myEnvelope = myEnvelope.withRecipients(new List<dfsle.Recipient> { myRecipient });
String templateId = 'envelope template id';
// myTemplateId contains the DocuSign Id of the DocuSign Template
dfsle.UUID myTemplateId = dfsle.UUID.parse(templateId);
// create a new document for the Envelope
dfsle.Document myDocument = dfsle.Document.fromTemplate(
myTemplateId,
'Opportunity Document');
Id myFileId = contentVersionId;
dfsle.Document myPdfDocument = dfsle.DocumentService.getDocuments(ContentVersion.getSObjectType(), new Set<Id> { myFileId }).get(0);
myDocument.withReplacement(myPdfDocument);
/*myDocument.withPdfOptions(new dfsle.Document.PdfOptions(
true, // Whether to transform PDF form fields
1)); // The recipient for which to apply the tags*/
//Add document to the Envelope
myEnvelope = myEnvelope.withDocuments(new List<dfsle.Document> { myDocument });
Account account = opportunityMap.get(opportunityId_i).Account;
myEnvelope = myEnvelope.withEmail(
'My Custom Email Subject',
'Thank you for your Interest' + opportunityMap.get(opportunityId_i).AdditionalEmailContent__c
);
System.debug('Document Subject: ' + myEnvelope.emailSubject);
// Send the envelope
myEnvelope = dfsle.EnvelopeService.sendEnvelope(
myEnvelope,
true);
When I debug the email subject, it is showing the custom email subject correctly. When I check Docusign Envelope (dfsle__Envelope__c). The records are showing the correct custom email subject and email message. However, as I mentioned before the recipient received email subject from the original Docusign Envelope Template. So the code is not overwriting the Email Subject.
How do I resolve this?