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
Guru@SfCloudGuru@SfCloud 

How to Split the Multiple CCAddresses in Trigger

Hi All,

I have requirement like based upon the multiple CCAddresses, for every CCAddress I need to create on CaseTeam Memeber under Case.

Can anyone suggest me How to split the CCAddress.

My code is 
Trigger Insert_CaseTeammember on EmailMessage (after insert) 
{   

 Set<String> EmailAddress = new Set<String>();
    Set<Id> ParId = new Set<Id>();
    
    for(EmailMessage Email: Trigger.new)
    {
        for(String Str:Email.CcAddress.Split(',',0))
        {
       
           EmailAddress.add(str);
         }
       
        ParId.add(Email.parentid);
    }
    
   
    List<Contact> listContacts = [Select Id,Email From Contact Where Email=:EmailAddress];
    CaseTeamRole role = [select Id from CaseTeamRole where Name =:'Backup FAE' limit 1];
    case cse=[select id,contactid from case where id=:ParId];
    
     List<CaseTeamMember> CaseTeam = new List<CaseTeamMember>();
     
       if(!listContacts.isempty())
        {    
          for(contact con:listContacts)
           {
              CaseTeamMember ct = new CaseTeamMember();
               ct.MemberId = con.Id;
               ct.ParentId = cse.id;
               ct.TeamRoleId = role.Id;
                
                CaseTeam.add(Ct);
                
               //insert ct;
           }  
        }
    
    if(!CaseTeam.isempty())
        {
        
        Insert CaseTeam;
        
        }     
 
 }

It is not working for multiple CCAddresses working for only one CCAddress.
Can any suggest where I did the Mistake .....this trigger needs to fire for Multiple CCAddresses.

If anyone help it would be greatly appreciated.

Thanks in Advance,
Gurunath Jinka.
James LoghryJames Loghry
I believe you want to split on ';' instead of ','.  A good way of finding this out is to debug the string (e.g. System.debug('EmailAddress CC String: ' + Email.CcAddress); ) and see how the multiple addresses are seprated.  You should also be able to test this out pretty easily with the developer console or execute anonymous.
Guru@SfCloudGuru@SfCloud
Thanks for your reply James!!!!

However I am not able to Kickoff this.

Can please provide any sample code that you have and that would be great help for me...!!!

Thanks in Advance,

Gurunath Jinka