From fed796e6cc57d1068dc7af064ad67e83b07b233d Mon Sep 17 00:00:00 2001 From: Paul Huliganga Date: Wed, 25 Feb 2026 17:33:42 -0500 Subject: [PATCH] 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' --- .../DocusignCompositeEnvelopeBuilder.cls | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/composite-envelope-builder/force-app/main/default/classes/DocusignCompositeEnvelopeBuilder.cls b/composite-envelope-builder/force-app/main/default/classes/DocusignCompositeEnvelopeBuilder.cls index 2b19bf9..c5c26a5 100644 --- a/composite-envelope-builder/force-app/main/default/classes/DocusignCompositeEnvelopeBuilder.cls +++ b/composite-envelope-builder/force-app/main/default/classes/DocusignCompositeEnvelopeBuilder.cls @@ -62,7 +62,7 @@ global with sharing class DocusignCompositeEnvelopeBuilder { List docNames = new List(); 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 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{ + ' - 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 buildErrorResult(String errorMessage) { DocusignEnvelopeResult result = new DocusignEnvelopeResult(); result.success = false;