+ Start a Discussion
Tad MatjusenkoTad Matjusenko 

Trigger throws an error if pick-list is empty

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.

Best Answer chosen by Tad Matjusenko
@anilbathula@@anilbathula@
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