You need to sign in to do that
Don't have an account?

Sort List or Map
Good day! I have two questions:
1. How to sort List?
2. How to sort the Map?
Sorting must take place not in the query.
Example:
Map <id,Action_Goal__c> aMap = new Map <id,Action_Goal__c> (
[select Goal_Description__c, id, Goal_Type__c, Targeted_Due_Date__c, Name, Status__c
From Action_Goal__c
Where ToLabel (Goal_Type__c) =: MyGoalType]);
List <Action_Goal__c> MyActGoalsDescList = aMap.values ();
I need to sort by Targeted_Due_Date__c.
The List object have sorting function, but I assume it won't help in case the type in the list is Object.
So I assume you will need to write your own sort function for this issue.
Maybe try something like...
List<myObject> sortedList=new List<myObject>();
while(originalList.size()>0)
{
myObject nextObj=originalList.get(0);
Integer nextObjIndex=0;
for(Integer index=0; index<originalList.size();index++)
{
if(tempObject.dateField < nextObj.dateField)
{
nextObj=tempObject;
nextObjIndex=index;
}
}
sortedList.add(originalList.remove(nextObjIndex));
}