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
Lukesh KarmoreLukesh Karmore 

how to send email to multiple releted contacts

Hello i write a trigger (When account type is update send mail to all releted contacts)
trigger WhenAccountTypeIsChange_SendEmailToAllReletedContacts on Account (After Update) {
set<id> AccountId=new set<id>();
for(account a:Trigger.new){
    if( a.type!=Trigger.oldMap.get(a.id).type){
        AccountId.add(a.id);
    }
}
list<Messaging.singleEmailMessage> mailList=new list<Messaging.singleEmailMessage>();
list<contact> contactlist=[select email from contact where AccountId in:AccountId];
for(account acc:Trigger.new){
    for(integer i=0; i<contactlist.size();i++){
        contact con=contactlist.get(i);
    Messaging.singleEmailMessage mail=new Messaging.singleEmailMessage();
    list<string> toAddress=new list<string>();
    toAddress.add(con.Email);
    mail.setTargetObjectId(con.id);
   mail.setToAddresses(toAddress);
    mail.setsubject('Account Update Info');
    mail.setHTMLBody('Your Account information Updated successfully.<br/>account Name: ' +acc.Name+
    '<br/>Your AccountType Is Changed To '+Acc.Type);
    mailList.add(mail);
    
}
}
Messaging.SendEmail(mailList);
}
but getting error
WhenAccountTypeIsChange_SendEmailToAllReletedContacts: execution of AfterUpdate caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: SINGLE_EMAIL_LIMIT_EXCEEDED, Email limit exceeded: [] Trigger.WhenAccountTypeIsChange_SendEmailToAllReletedContacts: line 26, column 1
i have 2 contacts releted to account but mail goes to 1st contact only is  there any way to send more than one person without referencing exact email id
Thank you
Suraj Tripathi 47Suraj Tripathi 47
Hi Lukesh,
Here I have provided you refrence link for your question in this example also send mail to multiple related contact .the is link is below;
https://salesforce.stackexchange.com/questions/129107/send-email-to-multiple-account-contacts

Thanks and Regards,
Suraj tripathi.