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;