+ Start a Discussion
Nihar Annamaneni 7Nihar Annamaneni 7 

How to write a trigger for When ever student record is deleted send them email

HI,
I have created an email template (Dear student , Your registration is deleted successfully. Thanks Capital Info) 
How to assign this email template to the trigger
Best Answer chosen by Nihar Annamaneni 7
Raj VakatiRaj Vakati
trigger SutdentDelete on Student__c(after delete) {

Messaging.reserveSingleEmailCapacity(2);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[];
for (Student__c std : Trigger.new) {

 toAddresses.add(std.email__c); 
 
}


mail.setToAddresses(toAddresses);
mail.setSubject('Record Deleted');
mail.setBccSender(false);
mail.setPlainTextBody('Dear student , Your registration is deleted successfully. Thanks Capital Info');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });


}