Skip to main content
Hello and thank you in advance,

I have this trigger: 

 

trigger preventSigAccDeletion on Account (before delete) {

for(Account acc : trigger.old){

if( acc.Contact_type__c.contains ('Signatory')

&& acc.Status__c == 'Approved'){

acc.adderror('Signatory Accounts cannot be deleted. Please contact administrator if you need it to be deleted or merged');

}}}

Contact_type__c is a multi picklist

Status__c is a standard picklist

When I try to delete record where Contact_type__c is blank then the code throws following error: 

Apex trigger preventSigAccDeletion caused an unexpected exception, contact your administrator: preventSigAccDeletion: execution of BeforeDelete caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.preventSigAccDeletion: line 3, column 1

Thank you all.

1 answer
  1. Jan 25, 2019, 11:15 AM
    Hi Tad,

    try this code:-

    trigger preventSigAccDeletion on Account (before delete) { for(Account acc : trigger.old){ if(acc.Contact_type__c!=null && acc.Contact_type__c.contains ('Signatory') && acc.Status__c == 'Approved'){ acc.adderror('Signatory Accounts cannot be deleted. Please contact administrator if you need it to be deleted or merged'); }}}

    Thanks

    Anil.B
0/9000