I need to make discount depends from Registration date (i.e. 3% discount to Opportunity when Accoun registered 1-2 years ago). Sample of code:
for (Opportunity opp : TriggeredOpps){
If (Account.Registration_Date__c != null){
Date todayDate = Date.today();
Date RegDay = opp.Account.Registration_Date__c;
Integer numberOfDays = RegDay.daysBetween(todayDate);
if(numberOfDays >= 365 || numberOfDays < 730 ){
for (Discount__mdt disc : DiscountRecords){
if(disc.Years_Sinse_Reg__c == 1){
opp.Amount = opp.Amount - (opp.Amount*(disc.Discount__c / 100));
}
}
}
}
}
but part Integer numberOfDays = RegDay.daysBetween(todayDate)
doesn't work.
Can somebody help with what is wrong here?
During manual testing
System.NullPointerException: Attempt to de-reference a null object Class.OpportunityTriggerHandler.DiscountOpportunityRegDay: line 48, column 1
line 48 - it's exactly Integer numberOfDays = RegDay.daysBetween(todayDate)