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
Gwirizanani SinoiaGwirizanani Sinoia 

Compare 5 date values against each other to which one is current

Hi all,

I am in the process of building a trigger that  compares 6 date values on an object against each other to see which one is current. What is the most effecient way to do this? The aim is to ensure that no value is left out in the logic.

Thanks in Advance
Alain CabonAlain Cabon
Hi,

"which one is current" what does that mean? There is a reference date range? (min date, max date, equals to current day? contained in a interval)

You should give an example.
Gwirizanani SinoiaGwirizanani Sinoia
For example 

Date 1 = 20/02/2018
Date  2 = 17/02/2018
Date 3 = 02/01/2018
Date 4 = 23/06/2018
Date 5 = 30/02/2018
Date 6 = 10/04/2018

The Idea is to check which is current among the 6 dates. The date range is random all depends on when they were last updated. Hope this makes sense. Finally when the current date is found populate the UpdateDate Field with the value from the 6 date fields.

 
Alain CabonAlain Cabon
Hi,

You don't explain the rule for choosing one date among the six shown above.

What date is current for you? The current date is today and so none of your six dates is "current".

Many people could help here but your explanation is not clear so no one help you until now.

Dictionary: current (adjective): belonging to the present time; happening or being used or done now.

None of your six dates is current (means 12/10/2018  = 12 october 2018 = Today).
Gwirizanani SinoiaGwirizanani Sinoia
Current date = today
 
Alain CabonAlain Cabon
It is a formula or in Apex ?

In Apex, you just store your values into a Set (if you want just to know that at least, one date is current) or a Map (if you want to know what date is current) and you use contains (Set) or containsKey (Map). But for only 6 values, it is a complication instead of comparing the six values with the current date using simple IF directly.

With a formula, you can use some nested IF. You will not do a dichotomic search with a formula.