function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mahesh p 54mahesh p 54 

How to display List<String> in Email Template through apex class

/*Send an email to Contractor / customer when Additional documents are Uploaded by Underwriter */
    @AuraEnabled
    public static void AdditionalDocumentsEmailIntimation(List<String> valueSet, Id oppId, String StageName){
        List<String> fileList = new List<String>();
        List<String> toAddress = new List<String> ();
        List<Verification_Documents__c> vd = new List<Verification_Documents__c> ([SELECT Id,Name,docType__c,Document_Name__c,Approved__c,Document_Master__r.Document_Name__c,Document_Master__r.DocumentType__c,Document_Master__r.User__c,Comment__c,
                                                                                   Document_Master__r.Stages__c,Opportunity__r.customer__r.email,Opportunity__r.OwnerId,Opportunity__r.Sales_Contractor__r.Id, 
                                                                                   Opportunity__r.Sales_Contractor__r.Email FROM Verification_Documents__c where Opportunity__r.Id = :oppId AND Document_master__r.Stages__c =: StageName AND Document_Master__r.DocumentType__c = 'Additional']);
        Map<String, Verification_Documents__c> mapDocNameVsVerificationDoc = new Map<String, Verification_Documents__c>();
        
        for(Verification_Documents__c vdc: vd){
            toAddress.clear();
            if(valueSet.contains(vdc.Document_Master__r.Document_Name__c) && vdc.Document_Master__r.User__c == 'Customer' && vdc.Document_Master__r.DocumentType__c == 'Additional'){
                system.debug('selectedVal'+valueSet.contains(vdc.Document_Master__r.Document_Name__c));
                System.debug('****For Customer ');
                toAddress.clear();
                toAddress.add(vdc.Opportunity__r.customer__r.Email);
                system.debug('vdc.Opportunity__r.customer__r.Email***'+vdc.Opportunity__r.customer__r.Email+'vdc.em'+vdc.Document_Name__c);
                System.debug('****In Email'+vdc.Opportunity__r.customer__r.Email);
                EmailTemplate emailTemp = [SELECT Id, Name, Body, HtmlValue FROM EmailTemplate where name='AdditionalDocumentsIntimation']; 
                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                email.setToAddresses(toAddress);
                email.setSenderDisplayName('OakStar Team');
                if(vdc.Document_Master__r.User__c  == 'Customer'){
                    email.setTargetObjectId(vdc.Opportunity__r.customer__r.Id);
                }
                email.setWhatId(vdc.Id);
                email.setTemplateId(emailTemp.id); 
                system.debug('vdc'+email);
                if(email != null){                
                    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email }); 
                }
            }
            else if(valueSet.contains(vdc.Document_Master__r.Document_Name__c) && vdc.Document_Master__r.User__c == 'Contractor' && vdc.Document_Master__r.DocumentType__c == 'Additional'){
                system.debug('selectedVal'+valueSet.contains(vdc.Document_Master__r.Document_Name__c));
                System.debug('****for Contractor ');
                toAddress.add(vdc.Opportunity__r.Sales_Contractor__r.Email);
                system.debug('vdc.Opportunity__r.Sales_Contractor__r.Email***'+vdc.Opportunity__r.Sales_Contractor__r.Email+'vdc.em'+vdc.Document_Name__c);
                System.debug('****In Email'+vdc.Opportunity__r.Sales_Contractor__r.Email);
                EmailTemplate emailTemp = [SELECT Id, Name, Body, HtmlValue FROM EmailTemplate where name='AdditionalDocumentsIntimation']; 
                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                email.setToAddresses(toAddress);
                email.setSenderDisplayName('OakStar Team');
                if(vdc.Document_Master__r.User__c  == 'Contractor'){
                    email.setTargetObjectId(vdc.Opportunity__r.Sales_Contractor__r.Id);
                }
                email.setWhatId(vdc.Id);
                email.setTemplateId(emailTemp.id); 
                system.debug('vdc'+email);
                if(email != null){                
                    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email }); 
                }
            }
            //}
        }     
    }
Currently my method is sending an email using an email Template each time a document of customer or contractor is added with a merge field of document name in the template.What i am looking for is if 2 documents of customer,contractor are added i need to send a two emails with string of document names in the template one to customer and one to contractor.