• Ben Olsen 37
  • NEWBIE
  • 10 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
im currently writing a trigger to send an email to the account owner, when a contact is deleted,  I am almost there,  can anyone point out where i am going wrong.  Also how do i write a test class for this?  Here is what i have so far I copied this and changed it to what i was needing,  but don't know how to reference the account owner email and where it goes,  is it owner.email?

trigger EmailAfterDelete on Contact (after delete) {
Messaging.reserveSingleEmailCapacity(trigger.size);
    List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
    for (Contact Contact : Trigger.old) {
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        email.setToAddresses(new String[] {'some email address'};);
        email.setSubject('Deleted Contact Alert');
        email.setPlainTextBody('This message is to alert you that the Contact named ' + Contact.Name +' on Account' + Account.Name +
                               ' has been deleted.');
        emails.add(email);
    }
    Messaging.sendEmail(emails);

}
im currently writing a trigger to send an email to the account owner, when a contact is deleted,  I am almost there,  can anyone point out where i am going wrong.  Also how do i write a test class for this?  Here is what i have so far I copied this and changed it to what i was needing,  but don't know how to reference the account owner email and where it goes,  is it owner.email?

trigger EmailAfterDelete on Contact (after delete) {
Messaging.reserveSingleEmailCapacity(trigger.size);
    List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
    for (Contact Contact : Trigger.old) {
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        email.setToAddresses(new String[] {'some email address'};);
        email.setSubject('Deleted Contact Alert');
        email.setPlainTextBody('This message is to alert you that the Contact named ' + Contact.Name +' on Account' + Account.Name +
                               ' has been deleted.');
        emails.add(email);
    }
    Messaging.sendEmail(emails);

}