You need to sign in to do that
Don't have an account?
Send Email Messaging
Hello Experts,
In my org, there are 3 Public group.PG-A,PG-B,PG-C.
PG-A has 2 Users having RCU Initiator profile.
PG-B and PG-C each has 1 user.
I have a requirment,
When Case passes from PG-A (RCU_Stage__c='RCU Initiator') user to PG-B (RCU_Stage__c='RCU Verification') to PG-C (RCU_Stage__c='RCU Completion'), Once RCU_Stage__c become 'RCU Completion', email should send to the User who passed the case to PG-B user.
Allocated_By__c is the case field which shows the User (Who send the case to 'RCU Verification' (PG-B) stage.
***I dont want to write HardCoded email id in sendTo***
My Code-
trigger sendEmailtoinitiator on Case (after update) {
//master list to hold the emails we'll send
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
for (Case newCase : Trigger.new){
if(newCase.RCU_Stage__c == 'RCU Completion' ){
//Create a new Email
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
//Setting list of people to get the email
List<String> sendTo = new List<String>();
// sendTo.add(newCase.Allocated_By_Text__c);
sendTo.add(newCase.Allocated_By__c);
mail.setToAddresses(sendTo);
//Setting ReplyTo email
mail.setReplyTo(newCase.OwnerId);
//list of people who should be CC
List<String> ccTo = new List<String>();
ccTo.add(newCase.CreatedById);
mail.setCcAddresses(ccTo);
//Email TemplateId (NOT SURE)
EmailTemplate et = [select id,Subject from EmailTemplate where developername='CaseStageEmailAlert'];
mail.setTemplateId(et.Id );
//Subject
//mail.setSubject('Case reached at Completion Stage');
mail.setSubject(et.Subject);
//adding email to master list
mails.add(mail);
}
}
//Send email to master list
Messaging.sendEmail(mails);
}