+ Start a Discussion
Soundar Raj PonpandiSoundar Raj Ponpandi 

Sending Email is not sending to CC Address

Hi,

I am sending a Eamil notification with classic template. Here i am mapping To address and CC address as well. But mail is not sending to CC Address, It's only sending to To address. 

Can you pelase check my code and guide me where i need to change a code.
 
if(firstLevelEscalation.size() > 0 && firstLevelEscalation.size() != null){
            for(GD_Lead__c lead : firstLevelEscalation){
            //Dummy Contact for Email Template
            Contact con = [select id, Email from Contact where email <> null limit 1];
            List<Messaging.SingleEmailMessage> lstMsgs = new List<Messaging.SingleEmailMessage>();
            Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage();
            EmailTemplate template = [select id from EmailTemplate where DeveloperName='GD_Lead_Escalation_Template' limit 1];
            msg.setTemplateId(template.id);
            msg.setWhatId(lead.id);
            msg.setTargetObjectId(con.id); 
            String[] repEamail = new String[] {lead.GD_Assigned_To_Email__c};
            String[] ccAddresses = new String[] {lead.GD_Level_1_Manager__c};
            system.debug('ccAddresses' + ccAddresses);
            msg.setToAddresses(repEamail); 
            msg.setCcAddresses(ccAddresses);
            lstMsgs.add(msg);
            system.debug('lstMsgs' + lstMsgs);
            Savepoint sp = Database.setSavepoint();
            Messaging.sendEmail(lstMsgs);
            Database.rollback(sp);
            List<Messaging.SingleEmailMessage> lstMsgsToSend = new List<Messaging.SingleEmailMessage>();
            for (Messaging.SingleEmailMessage email : lstMsgs) {
                Messaging.SingleEmailMessage emailToSend = new Messaging.SingleEmailMessage();
                emailToSend.setToAddresses(email.getToAddresses());
                emailToSend.setPlainTextBody(email.getPlainTextBody());
                emailToSend.setHTMLBody(email.getHTMLBody());
                emailToSend.setSubject(email.getSubject());
                lstMsgsToSend.add(emailToSend);
                }
            Messaging.sendEmail(lstMsgsToSend);
        
        }
        }

Thanks & Regards,
Soundar. 
Best Answer chosen by Soundar Raj Ponpandi
Abhishek BansalAbhishek Bansal
Hi Soundar,

I can see you are not using setCCAddress in the below code block. PLease add this line:
emailToSend.setCcAddresses(email.getccAddresses());

Thanks,
Abhishek Bansal.