Email To, CC Split in custom lable
String timeSheetApproverMail=System.Label.Domestic_AAW_Emails; //Custome Lable
List<String> getEmails = new List<String>();
getEmails.add(timeSheetApproverMail);
List<String> lst = new List<String>();
lst.add('{To:mailto@gmail.com,mailtocomma@gmail.com}-{CC:mailcc@gmail.com}');
lst.add('{To:mailto1@gmail.com}-{CC:mailcc1@gmail.com,mailcc2@gmail.com,mailcc3@gmail.com,mailcc4@gmail.com}');
lst.add('{To:mailto3@gmail.com}-{CC:mailcc5@gmail.com}');
lst.add('{To:mailto4@gmail.com}-{CC:mailcc6@gmail.com}');
lst.add('{To:mailto5@gmail.com}-{CC:mailcc7@gmail.com}');
lst.add('{To:mailto6@gmail.com}-{CC:mailcc8@gmail.com,mailcc9@gmail.com,mailcc10@gmail.com,mailcc11@gmail.com}');
List<String> toEmail = new List<String>();
List<String> ccEmail = new List<String>();
for(String s:lst){
if(s.contains('-')){
List<String> temp = s.split('-');
for(String innerEmail:temp){
if(!innerEmail.contains(',')){
if(innerEmail.contains('To')){
toEmail.add(innerEmail.split(':')[1].Substring(0,innerEmail.split(':')[1].length()-1).replaceAll('\r\n|\n|\r','').replaceAll('}','').trim());
}else{
ccEmail.add(innerEmail.split(':')[1].Substring(0,innerEmail.split(':')[1].length()-1).replaceAll('\r\n|\n|\r','').replaceAll('}','').trim());
}
}else if(innerEmail.contains(',')){
if(innerEmail.contains('To')){
String tempRemove = innerEmail.split(':')[1];
for(String item:tempRemove.replaceAll(',',':').split(':')){
toEmail.add(item.replaceAll('\r\n|\n|\r','').replaceAll('}','').trim());
}
}else{
String tempRemove = innerEmail.split(':')[1];
for(String item:tempRemove.replaceAll(',',':').split(':')){
ccEmail.add(item.replaceAll('\r\n|\n|\r','').replaceAll('}','').trim());
}
}
}
}
}
}
for(String to:toEmail){
System.debug(to);
}
System.debug('||||||||||||||||||||||||||||||||||||||||||||||||||||||||');
for(String cc:ccEmail){
System.debug(cc);
}
Great bro
ReplyDelete