function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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