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
Vipin K 10Vipin K 10 

Send Email to Multiple Account Contacts

Hi All,
I have a scenario where i need to send email to multiple contacts.

Under account contact we seperate some conact with type - 'Approvers' and one account can have multiple contacts with type Approvers.
When a oppty status is changed to status 'Need Review' an email should be sent to all account contacts with type approvers.

How can we configure this?
Rakesh51Rakesh51
You can eithe ruse apex trigger. This code snippet may help to your scenario.
trigger Trigger Name on Opportunity
Set<Id> accIds = new Set<Id>();

if(trigger.isUpdate && trigger.isBefore) {
    for(Opportunity opp : trigger.new) {
        if(opp.AccountId <> null && opp.stageName = 'Need Review'Trigger.OldMap.get(opp.Id).stageName && opp.stageName == 'Need Review') {
            accIds.add(opp.AccountId);
        }
    }
} 

if(accIds.size() > 0) {
    List<Messaging.SingleEmailMessage> emailList = new List<Messaging.SingleEmailMessage>();
    for(Contact con : [Select Id, Email FROM Contact WHERE AccountId IN :accIds AND Email <> null AND Type__c = 'Approvers']) {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setToAddresses(new List<String> {con.Id});
        mail.setSubject('Test Subject');
        mail.setPlainTextBody('Test Mail');
        emailList.add(mail);
    }
    if(emailList.size() > 0) {
        Messaging.sendEmail(emailList);
    }
}

 
Hannah ButcherHannah Butcher
I have a very similar situation; however, I also need to set everyone without that designation to the cc line (mail.setCCaddresses). How would you adjust to pull those in? Would this be a nested if statement?