feat: concatenate template names for Document Name, strip language suffix
- First document label is now all template names joined with ', ' - Strips ' - English', ' - Spanish', ' - French' suffixes (case-insensitive) - Truncates to 255 chars with '...' if too long - Docusign Status now shows e.g. 'Admin Unit Notification, Consent to Eval' instead of 'Template 89dd5ead'
This commit is contained in:
parent
978051bf49
commit
fed796e6cc
|
|
@ -62,7 +62,7 @@ global with sharing class DocusignCompositeEnvelopeBuilder {
|
|||
List<String> docNames = new List<String>();
|
||||
for (String templateId : sortedTemplateIds) {
|
||||
String label = templateNames.containsKey(templateId)
|
||||
? templateNames.get(templateId)
|
||||
? stripLanguageSuffix(templateNames.get(templateId))
|
||||
: templateId;
|
||||
documents.add(
|
||||
dfsle.Document.fromTemplate(
|
||||
|
|
@ -74,6 +74,21 @@ global with sharing class DocusignCompositeEnvelopeBuilder {
|
|||
}
|
||||
myEnvelope = myEnvelope.withDocuments(documents);
|
||||
|
||||
// Set combined template names as the envelope document name
|
||||
// (shows in Docusign Status "Document Name" column)
|
||||
String combinedName = String.join(docNames, ', ');
|
||||
if (combinedName.length() > 255) {
|
||||
combinedName = combinedName.left(252) + '...';
|
||||
}
|
||||
// Use combined name as the first document label so it appears in Status
|
||||
if (!documents.isEmpty()) {
|
||||
documents[0] = dfsle.Document.fromTemplate(
|
||||
dfsle.UUID.parse(sortedTemplateIds[0]),
|
||||
combinedName
|
||||
);
|
||||
myEnvelope = myEnvelope.withDocuments(documents);
|
||||
}
|
||||
|
||||
// Resolve recipients from Client_Case__c lookup fields
|
||||
List<dfsle.Recipient> recipients = resolveRecipients(req.recordId);
|
||||
myEnvelope = myEnvelope.withRecipients(recipients);
|
||||
|
|
@ -204,6 +219,28 @@ global with sharing class DocusignCompositeEnvelopeBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Strips language suffixes like " - English" or " - Spanish" from template names
|
||||
* @param name Template name
|
||||
* @return Cleaned template name
|
||||
*/
|
||||
@TestVisible
|
||||
private static String stripLanguageSuffix(String name) {
|
||||
if (String.isBlank(name)) return name;
|
||||
// Remove common language suffixes (case-insensitive)
|
||||
String cleaned = name;
|
||||
for (String suffix : new List<String>{
|
||||
' - English', ' - Spanish', ' - French',
|
||||
' - Anglais', ' - Espagnol', ' - Français'
|
||||
}) {
|
||||
if (cleaned.endsWithIgnoreCase(suffix)) {
|
||||
cleaned = cleaned.left(cleaned.length() - suffix.length());
|
||||
break;
|
||||
}
|
||||
}
|
||||
return cleaned.trim();
|
||||
}
|
||||
|
||||
private static List<DocusignEnvelopeResult> buildErrorResult(String errorMessage) {
|
||||
DocusignEnvelopeResult result = new DocusignEnvelopeResult();
|
||||
result.success = false;
|
||||
|
|
|
|||
Loading…
Reference in New Issue