Fix email subject to use combined template Short Names
- Query Short_Name__c field from dfsle__EnvelopeConfiguration__c - Use short names for email subject (fallback to full names if blank) - Custom emailSubject still overrides if provided - Always truncate subject to 100 characters max - Fixes issue where selecting all templates created too-long subject
This commit is contained in:
parent
90c65ea2c6
commit
32369c5939
|
|
@ -48,18 +48,23 @@ global with sharing class DocusignCompositeEnvelopeBuilder {
|
||||||
List<String> sortedTemplateIds = new List<String>(new Set<String>(req.templateIds));
|
List<String> sortedTemplateIds = new List<String>(new Set<String>(req.templateIds));
|
||||||
sortedTemplateIds.sort();
|
sortedTemplateIds.sort();
|
||||||
|
|
||||||
// Query template names for document labels (shows in Docusign Status)
|
// Query template names and short names for document labels and email subject
|
||||||
Map<String, String> templateNames = new Map<String, String>();
|
Map<String, String> templateNames = new Map<String, String>();
|
||||||
|
Map<String, String> templateShortNames = new Map<String, String>();
|
||||||
for (dfsle__EnvelopeConfiguration__c config : [
|
for (dfsle__EnvelopeConfiguration__c config : [
|
||||||
SELECT dfsle__DocuSignId__c, Name
|
SELECT dfsle__DocuSignId__c, Name, Short_Name__c
|
||||||
FROM dfsle__EnvelopeConfiguration__c
|
FROM dfsle__EnvelopeConfiguration__c
|
||||||
WHERE dfsle__DocuSignId__c IN :sortedTemplateIds
|
WHERE dfsle__DocuSignId__c IN :sortedTemplateIds
|
||||||
]) {
|
]) {
|
||||||
templateNames.put(config.dfsle__DocuSignId__c, config.Name);
|
templateNames.put(config.dfsle__DocuSignId__c, config.Name);
|
||||||
|
if (String.isNotBlank(config.Short_Name__c)) {
|
||||||
|
templateShortNames.put(config.dfsle__DocuSignId__c, config.Short_Name__c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<dfsle.Document> documents = new List<dfsle.Document>();
|
List<dfsle.Document> documents = new List<dfsle.Document>();
|
||||||
List<String> docNames = new List<String>();
|
List<String> docNames = new List<String>();
|
||||||
|
List<String> subjectNames = new List<String>();
|
||||||
for (String templateId : sortedTemplateIds) {
|
for (String templateId : sortedTemplateIds) {
|
||||||
String label = templateNames.containsKey(templateId)
|
String label = templateNames.containsKey(templateId)
|
||||||
? stripLanguageSuffix(templateNames.get(templateId))
|
? stripLanguageSuffix(templateNames.get(templateId))
|
||||||
|
|
@ -71,6 +76,12 @@ global with sharing class DocusignCompositeEnvelopeBuilder {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
docNames.add(label);
|
docNames.add(label);
|
||||||
|
|
||||||
|
// Use short name for email subject if available, otherwise use regular name
|
||||||
|
String subjectName = templateShortNames.containsKey(templateId)
|
||||||
|
? templateShortNames.get(templateId)
|
||||||
|
: label;
|
||||||
|
subjectNames.add(subjectName);
|
||||||
}
|
}
|
||||||
myEnvelope = myEnvelope.withDocuments(documents);
|
myEnvelope = myEnvelope.withDocuments(documents);
|
||||||
|
|
||||||
|
|
@ -93,13 +104,15 @@ global with sharing class DocusignCompositeEnvelopeBuilder {
|
||||||
List<dfsle.Recipient> recipients = resolveRecipients(req.recordId);
|
List<dfsle.Recipient> recipients = resolveRecipients(req.recordId);
|
||||||
myEnvelope = myEnvelope.withRecipients(recipients);
|
myEnvelope = myEnvelope.withRecipients(recipients);
|
||||||
|
|
||||||
// Set email subject if provided (truncated to 100 chars max)
|
// Set email subject to combined template short names (or custom subject if provided)
|
||||||
if (String.isNotBlank(req.emailSubject)) {
|
String emailSubject = String.isNotBlank(req.emailSubject)
|
||||||
String truncatedSubject = req.emailSubject.length() > 100
|
? req.emailSubject
|
||||||
? req.emailSubject.left(97) + '...'
|
: String.join(subjectNames, ', ');
|
||||||
: req.emailSubject;
|
// Truncate to 100 characters maximum as required by Docusign
|
||||||
myEnvelope = myEnvelope.withEmail(truncatedSubject, '');
|
if (emailSubject.length() > 100) {
|
||||||
|
emailSubject = emailSubject.left(97) + '...';
|
||||||
}
|
}
|
||||||
|
myEnvelope = myEnvelope.withEmail(emailSubject, '');
|
||||||
|
|
||||||
// Send the envelope
|
// Send the envelope
|
||||||
myEnvelope = dfsle.EnvelopeService.sendEnvelope(myEnvelope, true);
|
myEnvelope = dfsle.EnvelopeService.sendEnvelope(myEnvelope, true);
|
||||||
|
|
|
||||||
|
|
@ -221,14 +221,14 @@ private class DocusignCompositeEnvelopeBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@isTest
|
@isTest
|
||||||
static void testWithEmailSubject() {
|
static void testCustomEmailSubject() {
|
||||||
// Arrange
|
// Arrange
|
||||||
dfsle.TestUtils.setMock(new dfsle.ESignatureAPIMock());
|
dfsle.TestUtils.setMock(new dfsle.ESignatureAPIMock());
|
||||||
|
|
||||||
DocusignEnvelopeRequest req = new DocusignEnvelopeRequest();
|
DocusignEnvelopeRequest req = new DocusignEnvelopeRequest();
|
||||||
req.templateIds = new List<String>{'01234567-abcd-ef01-2345-6789abcdef01'};
|
req.templateIds = new List<String>{'01234567-abcd-ef01-2345-6789abcdef01'};
|
||||||
req.recordId = '001000000ABC123';
|
req.recordId = '001000000ABC123';
|
||||||
req.emailSubject = 'Custom: Please review and sign';
|
req.emailSubject = 'Custom: Please review and sign'; // Custom subject overrides template names
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
Test.startTest();
|
Test.startTest();
|
||||||
|
|
@ -243,14 +243,14 @@ private class DocusignCompositeEnvelopeBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@isTest
|
@isTest
|
||||||
static void testWithoutEmailSubject() {
|
static void testEmailSubjectFromTemplateNames() {
|
||||||
// Arrange
|
// Arrange
|
||||||
dfsle.TestUtils.setMock(new dfsle.ESignatureAPIMock());
|
dfsle.TestUtils.setMock(new dfsle.ESignatureAPIMock());
|
||||||
|
|
||||||
DocusignEnvelopeRequest req = new DocusignEnvelopeRequest();
|
DocusignEnvelopeRequest req = new DocusignEnvelopeRequest();
|
||||||
req.templateIds = new List<String>{'01234567-abcd-ef01-2345-6789abcdef01'};
|
req.templateIds = new List<String>{'01234567-abcd-ef01-2345-6789abcdef01'};
|
||||||
req.recordId = '001000000ABC123';
|
req.recordId = '001000000ABC123';
|
||||||
req.emailSubject = null;
|
req.emailSubject = null; // No custom subject provided - should use combined template names
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
Test.startTest();
|
Test.startTest();
|
||||||
|
|
@ -261,7 +261,7 @@ private class DocusignCompositeEnvelopeBuilderTest {
|
||||||
Test.stopTest();
|
Test.stopTest();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
System.assertEquals(true, results[0].success, 'Should succeed without subject');
|
System.assertEquals(true, results[0].success, 'Should succeed with auto-generated subject from template names');
|
||||||
}
|
}
|
||||||
|
|
||||||
@isTest
|
@isTest
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue