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
AkiraDioAkiraDio 

Sort selection

Good day!
I'm having trouble sorting out the sample object.

Sort by Order by does not help (

 

Here is the code of the sample:

              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, CreatedDate, Agreed_Commitment__c, Coaching_Focus__c, Comments__c, Team_Member__c, Team_Member__r.Name
                                    From Action_Goal__c
                                    Where ToLabel(Goal_Type__c) =:MyGoalType
                                       AND ((CALENDAR_Year(Targeted_Due_Date__c)= :MyYear AND CALENDAR_Month(Targeted_Due_Date__c)= :MyMonth)
                                            OR ( Status__c !=:BusinessPlanUtil.Completed ) )
                                       AND (CreatedById =:MyUserID) order by Targeted_Due_Date__c]);

 I need to sort by Targeted_Due_Date__c. But sampling with sorting does not work.

Just in case the page and post the code of the controller.

page:

<apex:repeat var="PP" value="{!OwnerChildUserIDList}" >
            <span style="color : #1F1F1F; font-size : 14px; font-weight: bold;">{!PP.Name}</span><br/><br/>
            <apex:repeat var="item" value="{!MyActGoalsDescList}" >
                <apex:DataTable value="{!MyMonthlyPlanID}" var="fg" styleClass="bhpb-act bhpb-base bot-margin row-highlight" columnsWidth="100px,100px,100px,50px, 30px, 30px" rendered="{!IF(item.Team_Member__r.Name == PP.Name,true,false)}">
                    <apex:column style="text-align: left;" headervalue="{!$Label.Coaching_Focus}" rendered="{!IF(item.Team_Member__r.Name == PP.Name,true,false)}">
                        <apex:commandLink action="{!OpenActivityDescDetail}" value="{!item.Coaching_Focus__c}">         
                                <apex:param name="adID" value="{!item.id}" />
                        </apex:commandLink>                      
                    </apex:column>  
                    <apex:column style="text-align: left;" headervalue="{!$Label.Agreed_Commitment}" value="{!item.Agreed_Commitment__c}" rendered="{!IF(item.Team_Member__r.Name == PP.Name,true,false)}"/>  
                    <apex:column style="text-align: left;" headervalue="{!$Label.Comments}" value="{!item.Comments__c}" rendered="{!IF(item.Team_Member__r.Name == PP.Name,true,false)}"/>              
                    <apex:column style="" headervalue="{!$Label.Goal_set_in}" rendered="{!IF(item.Team_Member__r.Name == PP.Name,true,false)}">
                        <apex:outputText value="{0,date,MMMM', 'yyyy}">
                            <apex:param value="{!item.CreatedDate}" /> 
                        </apex:outputText>
                    </apex:column>
                    <apex:column style="" headervalue="{!$Label.Due_Date}" rendered="{!IF(item.Team_Member__r.Name == PP.Name,true,false)}">  
                         <apex:outputText value="{0,date,MM'/'dd'/'yyyy}">
                            <apex:param value="{!item.Targeted_Due_Date__c}" /> 
                        </apex:outputText>
                    </apex:column>     
                    <apex:column style="" headervalue="{!$Label.Status}" value="{!item.Status__c}" rendered="{!IF(item.Team_Member__r.Name == PP.Name,true,false)}"/>                       
                </apex:DataTable> 
               <c:MyActionGoals Lang="{!MyLang}" ActionGoalID="{!item.ID}" UserType="{!MyUserType}" MyActGoals="{!MyActGoals}" Year="{!MyYear}" Month="{!MyMonth}" UserID="{!MyUserID}" MyMonthlyPlanID="{!MyMonthlyPlanID}" rendered="{!IF(item.Team_Member__r.Name == PP.Name,true,false)}" IsPrint="{!isPrint}" />
             </apex:repeat> 
             <br/>
</apex:repeat>

 

 

controller:

public with sharing class MyActionTeamGoalsDesc_controller
{
  public String Mylang {get;set;}
   public String MyMonthlyPlanID {get;set;}
   public Integer MyYear {get;set;}
   public Integer MyMonth {get;set;}
   public String MyGoalType {get;set;}
   public String MyUserType {get;set;}
   public String  adID {get; set;}
   public String  prefix {get; set;}
   public String MyUserID  {get;set;}
   public Boolean Flag {get; set;}

   public List<MyActGoals__c> MyActGoals {get;set;}
   

      public List<User> OwnerChildUserIDList
    {
        get
        {
        List<User> UserIDList = new List<User>();   
        List<User> UserRoleId = new List<User>([select UserRoleId
                               from User 
                               where ID =:MyUserID]);    
            
        List<User> ChildUserList =new List<User>([select Name 
                                   from User 
                                   where UserRole.ParentRoleId =:UserRoleId[0].UserRoleId
                                    and IsActive =true ORDER by Name]);             
         
                for(User user:ChildUserList)
                {
                    UserIDList.add(user);
                }
                                                                 
        return         UserIDList;    
        }
        set;    
    
   }  
   

   // get MyYear MyMonth, not completed action plan(goal) description group by action plan type for MyUserID
   public List<Action_Goal__c> MyActGoalsDescList
   {
      get
      {
            Flag = false;   
          List<Action_Goal__c> MyActGoalsDescList = new List<Action_Goal__c>();
          if ((MyGoalType != null) && (MyGoalType !=''))
          {

//              Date MyDate = getStartDate();
              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, CreatedDate, Agreed_Commitment__c, Coaching_Focus__c, Comments__c, Team_Member__c, Team_Member__r.Name
                                    From Action_Goal__c
                                    Where ToLabel(Goal_Type__c) =:MyGoalType
                                       AND ((CALENDAR_Year(Targeted_Due_Date__c)= :MyYear AND CALENDAR_Month(Targeted_Due_Date__c)= :MyMonth)
                                            OR ( Status__c !=:BusinessPlanUtil.Completed ) )
                                       AND (CreatedById =:MyUserID) order by Targeted_Due_Date__c]);
                
              if (aMap.isEmpty())
              {
                Action_Goal__c tmp = new Action_Goal__c();
                tmp.Goal_Description__c =' ';
                MyActGoalsDescList.add(tmp);
              }
              else
              {
                MyActGoalsDescList = aMap.values() ;
                //MyActGoalsDescList.sort();
                MyActGoals= new List<MyActGoals__c> ();
                Set<id> whatIDSet = aMap.keySet() ;
                MyActGoals = getMyActGoalsList(whatIDSet);
              }
              Flag = true;
          }
         return MyActGoalsDescList;
    }
    set;
   }




// Click Open action Plan detail
   public PageReference OpenActivityDescDetail()
   {
     adID = System.currentPageReference().getParameters().get('adID');


     PageReference ActDescPage = new PageReference('/' + adID );
     return ActDescPage;
   }

   private List<MyActGoals__c> getMyActGoalsList(set<id> whatIDSet)
   {

          List<MyActGoals__c> MyActGoalsList = new List<MyActGoals__c>();

          if (!(whatIDSet.isEmpty()))
          {
            //get Task Information
             for (Task Tk : [select WhatID,Type__c,Subject,Who.firstname,Who.lastname,Purpose__c,Status,ActivityDate,ID, Description
                             From Task
                             Where (WhatID IN :whatIDSet)  AND (OwnerId =:MyUserID)
                             order by ActivityDate
                             ])
             {
               MyActGoals__c tmp = new MyActGoals__c();
               tmp.Goal_Description__c =Tk.WhatID;
               tmp.Due_Date__c = Tk.ActivityDate ;
               tmp.Status__c = Tk.Status;
               tmp.What_is_the_Purpose__c = Tk.Subject;
               tmp.What_is_the_Activity__c = Tk.Type__c;
               tmp.ID__c = Tk.ID;
               tmp.Who_is_it_With__c =Tk.Who.firstname+' ' +Tk.Who.lastname;
               IF(tmp.Who_is_it_With__c=='null null') {tmp.Who_is_it_With__c = System.Label.Not_Assigned;}
               tmp.Comments__c = Tk.Description;    

               MyActGoalsList.add(tmp);
             }

             //get Event Information
             for (Event ev : [select WhatID,Type__c,Subject,Who.firstname,Who.lastname,ActivityDate, EndDateTime,Account.Name, ID, Description
                                   From Event
                                    Where (WhatID IN :whatIDSet) AND (OwnerId =:MyUserID)
                                     order by WhatID
                                  ])
             {
                  MyActGoals__c tmp = new MyActGoals__c();
                  tmp.Goal_Description__c = ev.WhatID;
                  tmp.Due_Date__c = ev.ActivityDate ;

                  tmp.What_is_the_Purpose__c = ev.Subject;
                  tmp.What_is_the_Activity__c = ev.Type__c;
                  tmp.Comments__c = ev.Description; 
                  tmp.ID__c = ev.ID;
                  tmp.Who_is_it_With__c =ev.Who.firstname+' ' +ev.Who.lastname;
                  IF(tmp.Who_is_it_With__c=='null null') {tmp.Who_is_it_With__c = System.Label.Not_Assigned;}

                   MyActGoalsList.add(tmp);
              }
         }
         else
         {
            MyActGoalsList = null;
         }
         return MyActGoalsList ;

   }

}