You need to sign in to do that
Don't have an account?
AmbigaRam
Sending mass email to users in queue and case team
Hi,
I wrote the following code for sending email notification to customer, contact and case owner (users in queue) when there is change in the case record.
the conditions are, sender address : contact email
CC address : Web email
BCC address : Case owner (users in queue) and users in Case Team.
For sending email to contact and webmail, I wrote.
trigger caseUpdationMailNotification on Case (after update) { Set<Id> conIds = new Set<Id>(); List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>(); for (Case c: trigger.new) { conIds.add(c.ContactId); } Map<Id, Contact> conMap = new Map<Id, Contact>([SELECT Id, Email FROM Contact WHERE Id In :conIds]); for (Case c : trigger.new) { Contact relatedCaseContact = conMap.get(c.ContactId); Messaging.SingleEmailMessage CaseNotificationmail = new Messaging.SingleEmailMessage(); CaseNotificationmail.setToAddresses(new List<String> { relatedCaseContact.Email }); CaseNotificationmail.setReplyTo('case2email@y-1zk8ulh2xsm24t92q30hootymudvrh3i38tjl5mli2n9yuqfiq.k-w0fefmaj.k.apex.sandbox.salesforce.com'); CaseNotificationmail.setSenderDisplayName('Salesforce Support'); string oldcomment = trigger.oldMap.get(c.id).Most_Recent_Case_Comment__c; string oldMsg = trigger.oldMap.get(c.id).Most_Recent_Email_Message__c; String oldStatus = trigger.oldMap.get(c.id).status; if (c.status != oldStatus) { CaseNotificationmail.setToAddresses(new List<String> { relatedCaseContact.Email }); If(c.SuppliedEmail!=null) { CaseNotificationmail.setCcAddresses(new List<string>{c.SuppliedEmail}); } CaseNotificationmail.setSubject(' Case Status updation : ' + 'Changed to ' + c.status + '. Case:' + c.CaseNumber); CaseNotificationmail.setPlainTextBody('Your case Status: ' + c.CaseNumber ); } else if((c.Most_Recent_Case_Comment__c != oldcomment)&&(oldcomment != null)) { CaseNotificationmail.setToAddresses(new List<String> { relatedCaseContact.Email }); If(c.SuppliedEmail!=null) { CaseNotificationmail.setCcAddresses(new List<string>{c.SuppliedEmail}); } CaseNotificationmail.setSubject(' New Case comment is inserted ' + 'in Case:' + c.CaseNumber); CaseNotificationmail.setPlainTextBody('New Case comment is inserted . and the casecomment is " ' +c.Most_Recent_Case_Comment__c + '" in Case Number:' + c.CaseNumber ); } else if ((c.Most_Recent_Email_Message__c != oldMsg)&&(oldMsg != null)) { CaseNotificationemail.setToAddresses(new List<String> { relatedCaseContact.Email }); If(c.SuppliedEmail!=null) { CaseNotificationmail.setCcAddresses(new List<string>{c.SuppliedEmail}); } CaseNotificationmail.setSubject(' New Case email message is inserted ' + 'in Case:' + c.CaseNumber); CaseNotificationmail.setPlainTextBody('New Email message is inserted . and the message is "' +c.Most_Recent_Email_Message__c + '" in Case Number:' + c.CaseNumber ); } else { CaseNotificationmail.setToAddresses(new String[] {'test.salesforceemail2case@gmail.com'}); CaseNotificationmail.setSubject(' Case is updated ' + 'in Case:' + c.CaseNumber); CaseNotificationmail.setPlainTextBody('Case is updated in Case Number:' + c.CaseNumber ); } mails.add(CaseNotificationmail); } Messaging.sendEmail(mails); }
But I dont have idea , how to send to the mass mail to case owner,
Can any one help for this?
Thanks.,
Ambiga