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 picklistWhen 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
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'); }}}ThanksAnil.B