You need to sign in to do that
Don't have an account?
Sorted sObject List using ORDER BY SOQL
All,
I have a requirement to get a sorted list of sObject ApexCode. For each sObject set the Status Field to a pre-defined value and update the List. To acheive this I have sorted query on the sObject which returns a List. For some reason the iteration over the sObject List using the for loop does not return the results in sorted order. Execution of query itself in Eclipse returns the sorted results.
Here is the psuedo-code (Apex Code). Can someone tell me what is missing here:
//Check 1::
List<sObject> resultList = [Select Id, Name from sObject where value >100 order by startDate asc];
for (sObject result: resultList)
{
// Check 2::
System.debug('result start Date='+result.startDate);
}
Here sObject is the custom object,
Sort Query returns the results in the required order
Iteration over the List is NOT ordered.
Any thoughts what am I missing here?
TIA
Rahul
Did Earlier try that as well - did not work.
If for some reason the iteration isn't ordered, you can always use:
for(i=0,i<resultList.size(),i++){
sObject thisSObject = resultList.get(i);
//DO YOUR LOGIC HERE
}