function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sriharisfdc reddysriharisfdc reddy 

open activies and closed activities sorting order

Hi one account have multple related list project and case.prject and case open and closed activities iam showing account page.but i want all 3 list i want sort order.based on the due date i want sort order.please help me.

public class TicketsAndOpenActivitiesController{
    public List<case> theCase {get;set;}
    public List<Project__c> theProject {get;set;}
    public List<Account> theAccount {get; set;}
    public List<OpenActivity> openActivities {get;set;}
    public List<ActivityHistory> historyList {get;set;}
    public List<OpenActivity> finalOpenList {get;set;}
    public List<ActivityHistory> finalCloseList {get;set;}
    public Account acc;
    public case acc1;
    public Project__c acc2;
    
    public TicketsAndOpenActivitiesController(ApexPages.StandardController controller){
        openActivities = new List<OpenActivity>();
        historyList = new List<ActivityHistory>();
 this.acc=(Account)controller.getRecord();
        
        theAccount = [SELECT id,name,(SELECT id,Subject,ActivitySubtype, Owner.Name,WhoId,Who.Name,WhatId,What.Name,what.type,
                                   IsTask, ActivityDate, Status, Priority, OwnerId FROM OpenActivities Where What.type='Account' ORDER BY ActivityDate DESC),(SELECT id,Subject,ActivitySubtype, Owner.Name,WhoId,Who.Name,WhatId,What.Name,what.type,
                                    ActivityDate,IsTask, Status, Priority, OwnerId FROM activityhistories Where What.type='Account' ORDER BY ActivityDate DESC) 
                   From Account where Id=:acc.id];
        
       for(Account acc : theAccount){
            if(acc.OpenActivities.size() > 0){
                openActivities.addAll(acc.OpenActivities);
                
             }
        }
        for(Account acc : theAccount){
            if(acc.activityhistories.size() > 0){
                historyList.addAll(acc.activityhistories);
                
             }
        }
        
        theCase = [SELECT id,CaseNumber,Subject ,AccountId,(SELECT Subject,Id,ActivitySubtype, Owner.Name,WhoId,Who.Name,WhatId,What.Name,What.type,IsTask,ActivityDate, Status, Priority, OwnerId FROM OpenActivities where what.type='case' ORDER BY ActivityDate DESC),
                   (SELECT id,Subject,ActivitySubtype, Owner.Name,WhoId,Who.Name,WhatId,What.Name,what.type,
                                    ActivityDate,IsTask, Status, Priority, OwnerId FROM activityhistories Where What.type='case' ORDER BY ActivityDate DESC)  
                   FROM case where AccountId=:acc.id];
        
        for(Case c : theCase){
            if(c.OpenActivities.size() > 0){
                openActivities.addAll(c.OpenActivities);
            }
        }
        for(Case c : theCase){
            if(c.activityhistories.size() > 0){
                historyList.addAll(c.activityhistories);
                
             }
        }
        
        
        theProject = [SELECT id ,Customer__c,(SELECT Subject,Id,Owner.Name,WhoId,Who.Name,WhatId,ActivitySubtype,What.type,What.Name,IsTask, ActivityDate, Status, Priority, OwnerId FROM OpenActivities where what.type='Project__c' ORDER BY ActivityDate DESC) ,
                      (SELECT id,Subject,ActivitySubtype, Owner.Name,WhoId,Who.Name,WhatId,What.Name,what.type,
                                    ActivityDate,IsTask, Status, Priority, OwnerId FROM activityhistories Where What.type='Project__c' ORDER BY ActivityDate DESC)
                     FROM Project__c where Customer__c=:acc.id];  
     
        for(Project__c Project : theProject){
            if(Project.OpenActivities.size() > 0){
                openActivities.addAll(Project.OpenActivities);
            }
        }
        for(Project__c Project : theProject){
            if(Project.activityhistories.size() > 0){
                historyList.addAll(Project.activityhistories);
                
             }
        }
}
}
 
sriharisfdc reddysriharisfdc reddy
Task
at3
Activity Related To: Account
Due Date: 05/23/2018
status: Not Started
Task
at1
Activity Related To: Account
Due Date: 05/02/2018
status: Not Started
Task
at2
Activity Related To: Account
Due Date: 05/01/2018
status: Not Started
Task
Sell Client on CRXISelect
Activity Related To: CRXISelect
Due Date: 05/12/2018
status: Not Started
Task
test4
Activity Related To: Ticket
Due Date: 05/09/2018
status: Not Started
Task
crxiselectupdate
Activity Related To: CRXISelect
Due Date: 05/04/2018
status: Not Started
Task
crxiselet test
Activity Related To: CRXISelect
Due Date: 05/03/2018
status: Not Started
Iam getting this list but  Due date i want sort.