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
Chidanand Magadum 24Chidanand Magadum 24 

NULL POINTER Exception while finding number of days between two dates

Hi,
I am getting null Pointer exception in this code while finding difference between two dates. Any workaround

Date d = Date.Today();
system.debug(d);
List<Account> AllAccounts= new List<Account>([select id,ARR__c,Relationship_Start_Date__c from Account]);
for(Account a:AllAccounts)
{

system.debug('Date==='+d);
system.debug('Trans Date'+a.Relationship_Start_Date__c);
Integer numberDaysDue= d.daysBetween(a.Relationship_Start_Date__c);
system.debug('Diff==='+numberDaysDue);
}
Tejpal KumawatTejpal Kumawat
Hello Chidanand Magadum,

Try this :
 
Date d = Date.Today();
system.debug(d);
List<Account> AllAccounts= new List<Account>([select id,ARR__c,Relationship_Start_Date__c from Account]);
for(Account a:AllAccounts){
if(a.Relationship_Start_Date__c != null){
	Integer numberDaysDue= d.daysBetween(a.Relationship_Start_Date__c);
		system.debug('Diff==='+numberDaysDue);
	}
}
If this answers your question then hit Like and mark it as solution!