I am using Salesforce Apex Toolkit to send DocuSign Email/Envelope. I want to set the email language programmatically via Apex based on the Recipient's email language on the Salesforce Contact record.
I am aware of “Custom email and language for each recipient” option. However, I had to disable it so that I could set Email Subject and Text dynamically via Apex. I am also aware that you can change the default language on the UI, but it will apply to all emails sent via DocuSign.
I have found this information about recipient on DocuSign developer guide, but it does not work since I am using namespace dfsle. I have added recipient.EmailSettings, but the email is still in English.
How do I resolve this?
Relevant Apex Code
dfsle.Envelope myEnvelope = dfsle.EnvelopeService.getEmptyEnvelope(
new dfsle.Entity(opportunityId));
Contact myContact = opportunityIdToContactIdMap.get(opportunityId);
dfsle.Recipient myRecipient = dfsle.Recipient.fromSource(
myContact.Name,
myContact.Email,
null,
'Signer',
new dfsle.Entity(myContact.Id));
dfsle.Recipient.EmailSettings emailSettings =
new dfsle.Recipient.EmailSettings(
'de',
'German',
'Email Subject',
'Email Text'
);
myRecipient = myRecipient.withEmailSettings(emailSettings);
myEnvelope = myEnvelope.withRecipients(new List<dfsle.Recipient> { myRecipient });
String templateId = 'template ID';
dfsle.UUID myTemplateId = dfsle.UUID.parse(templateId);
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);
myEnvelope = myEnvelope.withDocuments(new List<dfsle.Document> { myDocument });
myEnvelope = myEnvelope.withEmail(
'Email Subject',
'Email Text'
);
myEnvelope = dfsle.EnvelopeService.sendEnvelope(
myEnvelope,
true);
EDIT 17.10: Add EmailSettings Code
I finally figured out how to do it. Recipient.EmailSettings is correct, but I have to fill the message and subject parameter with 'null' so it will go with the system default. If you fill the message and subject, it will use your default user language instead of the language parameter on the EmailSettings.
dfsle.Recipient.EmailSettings emailSettings =
new dfsle.Recipient.EmailSettings(
'de',
'German',
null,
null
);
myRecipient = myRecipient.withEmailSettings(emailSettings);