+ Start a Discussion
Vetriselvan ManoharanVetriselvan Manoharan 

Sort a list based on the created date


I want to sort the list based on the field
List<Hydra_ConversationView> theGroups = new List<Hydra_ConversationView>();
Hydra_ConversationView cbGroup;

// Get the Recent Message to be displayed 
        Map<id, FeedItem> feedMap = new Map<id, FeedItem>();
        Map<id, FeedItem> queryLatestMessage = new Map<id, FeedItem>([SELECT CreatedDate, body, Id FROM FeedItem where ParentId=:parentIds AND NetworkScope = 'AllNetworks' AND Visibility = 'AllUsers' ORDER BY CreatedDate DESC LIMIT : 1]);           
        for (FeedItem feed : queryLatestMessage.values()) {
          feedMap.put(feed.parentId, feed);
        for (Hydra_ConversationView cGroup : theGroups) {
          if (feedMap.ContainsKey(cGroup.Id)) {                        
              System.debug('Found group id in image map: ' + cGroup.IconId);                        
              FeedItem fi = feedMap.get(cGroup.Id);              
              cGroup.RecentMessage = fi.body;
        return theGroups;

I want to get the List of Groups based on the feed date.. If it is standard chatter group we can use the lastModifiedFeedDate..

Deepali KulshresthaDeepali Kulshrestha
Hi Vetriselvan,
Please try below code on your object, it may be helpful to you.

List<Account> listAccount = [Select createddate from Account limit 15];    
List<DateTime> listDate = new List<DateTime>();    
for(Account a : listAccount) {    
//Dates before sorting (This will not show you a sorted list)    
System.debug('the dates sorted are'+ json.serializepretty(listDate));

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha