You need to sign in to do that
Don't have an account?
Andrew marshal 3
Trigger on update , insert and delete
Any one please advise me how to write a trigger that will send an email to alert when that record is created or updated or deleted.
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
String subject = 'Record Change Alert';
String body = 'A record has been created, updated, or deleted.';
List<String> toAddresses = new List<String>{'example@email.com'};
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setToAddresses(toAddresses);
email.setSubject(subject);
email.setPlainTextBody(body);
Messaging.SendEmailResult[] results = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
}
Can you specify the parent object on which you want your trigger on ?
Thank you.
If you find this answer helpful, Please mark it as the best answer.
This trigger will help you to send email to all the contacts in the record i.e the emails mentioned in the record of that object.
trigger EmailObjectTrigger on Object__c (After insert,After update,After delete) {
list<String> emailAddress=new list<String>();
for(Object__c obj:trigger.new){
if(obj.Email_field__c!=null){
emailAddress.add(obj.Email_field__c);
}
}
if(!emailAddress.isEmpty()){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(emailAddress);
mail.setSubject('Record Change Alert');
mail.setPlainTextBody('The record has been created,deleted or updated.');
Messaging.sendEmail(new List<Messaging.SingleEmailMessage>{mail});
}
}
I hope this helps you!
Thanks.