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
SFDC12SFDC12 

single email help

Hi everyone Iam able to send mail when update happens in account related contact details but i need to get only one mail it contains these many contacts but am getting how many contacts means that many mails.ishould get only one mail says u have these may contacts please help,tried so far..
  

Trigger:
trigger semdmailfromacc on Account (after update) {
set<id> AccIds = new set<id>();
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
for(Account Acc: trigger.new){
AccIds.add(Acc.Id);
}
list<Contact> Con = [Select Id,Accountid,FirstName,LastName,Email from Contact Where AccountId in :AccIds];
for(Contact cc: Con){
if (cc.Email != null && cc.FirstName != null) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
List<String> sendTo = new List<String>();
sendTo.add(cc.Email);
mail.setToAddresses(sendTo);
mail.setSubject('Contact Details');
String body = 'Dear'+cc.LastName+ '<a href="'+URL.getSalesforceBaseUrl().toExternalForm()+'/'+cc.id+'">Click Here</a>';
body += 'This is the Account';
body += 'related Contact ';
body += 'with details.';
mail.setHtmlBody(body);
mails.add(mail);
}
}
Messaging.sendEmail(mails);
}
AnkaiahAnkaiah (Salesforce Developers) 
Hi Sfdc,

You need to send an email to invidual contacts or account owner saying that you have these many contacts?

Thanks!!