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

Please help newbie--days between date and datetime field?

I've got a trigger that needs to specify a picklist value based on the number of days between two fields, but one is a date and one is a datetime. I'm trying to use the date method to convert the datetime before using daysbetween, but can't figure out how to get it to work. I'm VERY new at triggers, so hopefully this should be straightforward....I just can't get it.


Trigger LateApp on opportunity(after update)
datetime dt1;
date dt2;
list<opportunity> opp=new list<opportunity>();
for(opportunity o :
{[0].Accepted__c;  *****do I add a .date here somewhere??****[0].Payment_ref__c;
if(dt1.daysBetween(dt2)+45 >= 45 || dt1.daysBetween(dt2)+45 < 75)
o.Payment_Plan__c ='Late1';
if(dt1.daysBetween(dt2)+45 >= 75 || dt1.daysBetween(dt2)+45 < 105)
o.Payment_Plan__c ='Late2';
if(dt1.daysBetween(dt2)+45 >= 105)
o.Payment_Plan__c ='Late3';
update opp;


Try the following


date dt1;
// ... //
dt1 =[0];

// or you can also cast it before calling daysBetween by ... // with dt1 as datetime