+ Start a Discussion
Salesforce Dev in TrainingSalesforce Dev in Training 

A workflow or approval field update caused an error when saving this record. Contact your administrator to resolve it. Next Payment Date: value not of required type: common.formula.FormulaEvaluationException: Month or Day out of range in DATE() function

Hello,

I am receiving the following error:

"A workflow or approval field update caused an error when saving this record. Contact your administrator to resolve it. Next Payment Date: value not of required type: common.formula.FormulaEvaluationException: Month or Day out of range in DATE() function"

When I change (on a custom object) the Last Payment Date / Next Payment date, it's causing this error which won't allow me to save any records.

I believe somewhere in this trigger is the error:

"1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
trigger RGNextPaymentDateUpdate on Recurring_Gift__c (before insert,before update) {
    for(Recurring_Gift__c rg : Trigger.new){
        system.debug('-----Last_date__c ------'+rg.Last_date__c );
        system.debug('------Recurrence_SchedulePL__c--------'+rg.Recurrence_SchedulePL__c);
        if(Trigger.isInsert){
            if(rg.Last_date__c !=null){
                if(rg.Recurrence_SchedulePL__c=='Monthly'){
                system.debug('-----Last_date__c ------'+rg.Last_date__c );
                    rg.Next_Payment_Date__c = (rg.Last_date__c).addMonths(1);
                }
                else if(rg.Recurrence_SchedulePL__c=='Yearly'){
                    rg.Next_Payment_Date__c = (rg.Last_date__c).addYears(1);
                }
            }
        }
        else if(Trigger.isUpdate){
            Recurring_Gift__c  rgOld = Trigger.oldMap.get(rg.Id);            
            if(rg.Last_date__c !=null && rg.Last_date__c != rgOld.Last_date__c  ){
                system.debug('-----Last_date__c ------'+rg.Last_date__c );
                if(rg.Recurrence_SchedulePL__c=='Monthly'){
                    rg.Next_Payment_Date__c = (rg.Last_date__c).addMonths(1);
                    system.debug('-----Recurrence_SchedulePL__c------'+rg.Recurrence_SchedulePL__c);
                }
                else if(rg.Recurrence_SchedulePL__c=='Yearly'){
                    rg.Next_Payment_Date__c = (rg.Last_date__c).addYears(1);
                    system.debug('-----Recurrence_SchedulePL__c------'+rg.Recurrence_SchedulePL__c);
                }
            }
        }
    }
}"

Our developers are out of office, and it's somewhat urgent, however, I'm not sure where I would go to fix the error or how I need to. Any help would be appreciated.