I have List of Records for which I want to find out Maximum value for particular Field:
Can anyone suggest me, any efficient way (rather than writing Sorting Method)
Example :
public decimal maxField1;
public decimal maxField2;
.....
{
List<MyObject__c> listMO = [SELECT ID, Team__c,Field1__c,Field2__c FROM MyObject__c WHERE xyz__c='abc'];
//Assume I have Map of Teams like below (Not used code here)
MyMap { (Team1,<MyObject1, MyObject2>),
(Team2,<MyObject3, MyObject4>)
}
//calling myMethod to get maximum
for(ID key :MyMap.keyset()){
myMethod(MyMap.get(key));
}
}
...
..
//Find maximum of Field1, field2 for each Team
//---right now I am using SOQL - which I dont want to use
public void myMethod(List<MyObject__c> lstParameter){
maxField1 = [SELECT Max(field1__c) FROM MyObject__c WHERE ID IN: lstParameter];
}
HERE : I dont want to use SOQL's anymore ....... is there any way that I can find out "Maximum of 'Field Value' for only given List of records at movement.
Any Suggestions! Help !
EDITS :
"Comparable Interface" is the one way - can anyone explain it with simplest real time example (Not Salesforce HelpPage)