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
Krishna_225Krishna_225 

Need to get record value whose date is less than all other records

Hello Admins and Developers,
I need to build a formula or process builder on Order object where the Order date is less than all other orders.
I know how to compare between two date fields but I'm bit confused here as we need to compare same date field between multiple records.
Can anyone please help me in this issue?

Thank you in advance,
Krish
Kakasaheb EKKakasaheb EK
Hi 
This can not be possible using validation rule or process builder because as we are iterating values and checking with small value.
So I would like to suggest here- write trigger on after insert on order object and apply below logic - 

public static int getSmallest(int[] a, int total){  
int temp;  
for (int i = 0; i < total; i++)   
        {  
            for (int j = i + 1; j < total; j++)   
            {  
                if (a[i] > a[j])   
                {  
                    temp = a[i];  
                    a[i] = a[j];  
                    a[j] = temp;  
                }  
            }  
        }  
       return a[0];  
}  


Please let me know your openion on this.

if you already resolved..please post your solution.

Regards,
Kakasaheb Ekshinge