0

I have this trigger to send an email when an attachment has been deleted.

trigger send_email on Attachment (after delete) {
    Attachment del = trigger.new[0];
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    String[] toAddresses = new string[] {'[email protected]'};
    mail.setToAddresses(toAddresses);
    mail.setReplyTo('[email protected]');
    mail.setSenderDisplayName('Salesforce Support');
    mail.setSubject('Attachment Deleted : ' + account.name);
    mail.setPlainTextBody('work please');
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}

but I get this message when I attempt to delete an attachment

send_email: execution of AfterDelete

caused by: System.NullPointerException: Attempt to de-reference a null object

Trigger.send_email: line 2, column 1

I just don't know enough to fix this.. any help? TIA

1 Answer 1

1

Delete triggers need to reference Trigger.old, not Trigger.new. Here are the docs on the context variables.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .