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
Steve CairneySteve Cairney 

Show MIN between two Datetime fields

Hi I have a datetime field called 'Last Contact'

This field shows the latest datetime from two other fields. Here's the code
 
NOW()- 
MIN( 
NOW()- MMERP__LastDatetimeSent__c , 
NOW()- Last_Call_Made__c 
)

It works fine, but if one of the fields is blank, the resulting field is blank.

How can I edit the formula above to post the datetime value from the filed that has a value out of the two?
SandhyaSandhya (Salesforce Developers) 
Hi Steve,

I think either of the code will work.(I have not tested)
 
now()-min(
if(isnull(now()-field1),0,now()-field1,
if(isnull(now()-field1),0,now()-field2
                    )

IF(AND(
  ISNULL(Date_Field_1__c),
  ISNULL(Date_Field_2__c)
  ),NULL,

  NOW()-MIN(
    NOW()-BLANKVALUE(Date_Field_1__c,DATE(1,1,1)),
    NOW()-BLANKVALUE(Date_Field_2__c,DATE(1,1,1))
))

Let me know if this helps you.

Thanks and Regards
Sandhya

 
Steve CairneySteve Cairney
Hi Sandhya, my fields are DateTime, what do I need to replace the DATE aspect in your 2nd code?
SandhyaSandhya (Salesforce Developers) 
Hi Steve,

Since DateTime is also datatype, you could probably use DateTime instead of Date.

Thanks and Regards
Sandhya
Steve CairneySteve Cairney
Hmm, adding DATEVALUE doesn't work, as there only needs to the one value after it, but above there are 3.
SandhyaSandhya (Salesforce Developers) 
Hi,

I said DATETIME not DATEVALUE.

Please see below link.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_datetime.htm
Thanks  and Regards
Sandhya
Steve CairneySteve Cairney
DATETIME isn't a variable in formula
SandhyaSandhya (Salesforce Developers) 
Hi Steve,

You are correct; DATETIME is not a variable in the formula.

I have worked around it and got below solution.It is working for me.
IF(date1__c<date2__c,
   date2__c,date1__c)


Please check and let me know if you have any more issues with this.

Thanks and Regards
Sandhya