You need to sign in to do that
Don't have an account?
SFDC12
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);
}
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);
}
You need to send an email to invidual contacts or account owner saying that you have these many contacts?
Thanks!!