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

Is it possible to store the previous value of for loop ?

I have requirement where I need to calculate max of actual date , I have 1 SOQL in my class which is ordered by Event_Sequence__c.
Iterating over the result of SOQL I am calculating the max date and the corresponding Event_Sequence__c  
I need to calculate date corresponding to  next_Event_Sequence__c
 next_Event_Sequence__c=Event_Sequence__c of max date + 1
But as my for loop is ORDERED By  Event_Sequence__c DESC so I will always get the higher Event_Sequence__c and then the lower Event_Sequence__c, so adding 1 to Event_Sequence__c of max date will always give higher value which loop has already processed.
Ex : If this is the result of SOQL
{"Event__c":"36_Shipment Delivered","Event_Sequence__c":36,"Actual_Date__c":null},
{"Event__c":"19_Shipment POD Discharge date","Event_Sequence__c:19":null,"Actual_Date__c":"2018-06-01"},
{"Event__c":"17_Shipment POL Depart date","Event_Sequence__c":17,"Actual_Date__c":"2017-12-20"},
{"Event__c":"15_Shipment ISF date","Event_Sequence__c":15,"Actual_Date__c":"2017-12-07"},
{"Event__c":"14_Shipment Manifest date","Event_Sequence__c":14,"Actual_Date__c":"2017-11-15"},
{"Event__c":"13_Shipment In Gate Origin POL date","Event_Sequence__c":13,"Actual_Date__c":"2018-07-15"},
So I should get max Actual_Date__c=2018-07-15 and Event_Sequence__c=13
but 14 is processed before 13 ,so I need to store record related to 14.