Skip to main content
I have a batch job that runs daily that simply looks for expired dates (compared with today) and marks a status "deactivated" if that date IS expired.

 

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';

}

}

 

 
3 件の回答
  1. 2020年2月24日 13:02
    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';

    }

     

     
0/9000