I recently added an && in there to check to see if those same date fields are NOT null/blank, but I must have written it incorrectly has the batch job is now not making contacts with expired fields "deactivated".
Where did I go wrong here?
global void execute(Database.BatchableContext bc, List<Contact> scope) {
for(Contact contactField : scope){
if(contactField.Clearance_Expires__c < todayDate && contactField.Clearance_Expires__c != null){
contactField.DIBNet_U_Status__c = 'Deactivated';
contactField.Contact_Status__c = 'Requires Action';
}
if(contactField.PKIExpires__c < todayDate && contactField.PKIExpires__c != null){
contactField.POC_Status__c ='Deactivated';
contactField.Contact_Status__c = 'Requires Action';
}
}
Checking for null should come first before other condition. Here is modified code if(contactField.Clearance_Expires__c != null && contactField.Clearance_Expires__c < todayDate){
contactField.DIBNet_U_Status__c = 'Deactivated';
contactField.Contact_Status__c = 'Requires Action';
}
if(contactField.PKIExpires__c != null && contactField.PKIExpires__c < todayDate){
contactField.POC_Status__c ='Deactivated';
contactField.Contact_Status__c = 'Requires Action';
}