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

sorting on sObject
i want to sort sObjects when click on an image
either i call a method for soritng or i i can fire a DML query ?
which method wud be most preferable in salesforce?
*i have to sort list of products in opportunity
if you can do this through query then obviously this is the best way.. if you have list of values which are not returned through query then u need to go with custom logic....
Thanks
i am very new in salesforce ..we are asked to fire minium query because of governors limits in salesforce. then also ur suggested method is better?
and one more thing can i get map by firing dynamic query?
i mean....
maps=new Map<id,Product>[query ]
in the [ ] i want to write dynamic query which usualy possible by database.query()? is it possible to get map any how?
Use this class for sort sObject.
Assign your oSbject list to the "originalList" property of ListSortHelper class. Then call the getSortedList(String fieldName, Boolean ascending) method. Then you will get the sorted list .
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
Creating a map<Id, sObject> from a list of sObjects will automatically create a map keyed by Id. However, in the past the map had to be strongly typed, I'm not sure this limitation still exists. For example, this should work:
Map<Id, Product> products = new Map<Id, Product>( Database.query( 'SELECT Id FROM Product WHERE Name LIKE \'' + nameParam + '%\'' ) );
You could also use apex-lang. I generally try to keep to sorting in my Query, but apex-lang can sort SObjects I believe.
http://code.google.com/p/apex-lang/