0

Below is my code for a Controller class called AssignmentsController. Assignments is a custom object that is related to Accounts. I have created a visual force component to display Assignments related to the Account. However I am having difficulty with the way Month/Date is displayed as I want to have it in descending order. Here is a picture the VisualForce component:

enter image description here

Code for Controller:

public with sharing class AssignmentsController { public Account currentAccount { get; set; } public List<Assignment__c> accountAssignments { get; set; }

public AssignmentsController(ApexPages.StandardController stdController) {
    this.currentAccount = (Account)stdController.getRecord();
    this.accountAssignments = [SELECT Id, Name, Type__c, Due_Date__c, Status__c, OwnerId, Owner.Name, Contact__c, Contact_Phone__c, Contact_Email__c 
                               FROM Assignment__c 
                               WHERE Account__c = :this.currentAccount.Id
                               ORDER BY Due_Date__c DESC];
                           
}

public void showMyAssignments() {
    this.accountAssignments = [SELECT Id, Name, Type__c, Due_Date__c, Status__c, OwnerId, Owner.Name, Contact__c, Contact_Phone__c, Contact_Email__c
                               FROM Assignment__c 
                               WHERE Account__c = :this.currentAccount.Id 
                               AND OwnerId = :UserInfo.getUserId()
                               ORDER BY Due_Date__c DESC];
}

public Map<String, List<Assignment__c>> getGroupedAssignments() {
    Map<String, List<Assignment__c>> assignmentsByMonthYear = new Map<String, List<Assignment__c>>();
    for (Assignment__c assignment : accountAssignments) {
        String monthYearKey = assignment.Due_Date__c.year() + '/' + assignMonthName(assignment.Due_Date__c.month());
        if (!assignmentsByMonthYear.containsKey(monthYearKey)) {
            assignmentsByMonthYear.put(monthYearKey, new List<Assignment__c>());
        }
        assignmentsByMonthYear.get(monthYearKey).add(assignment);
    }
    return assignmentsByMonthYear;
}


private String assignMonthName(Integer monthNum) {
    String[] monthNames = new String[]{'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'};
    return monthNames[monthNum-1];
}

}

Any help much appreciated :)

0

You must log in to answer this question.

Browse other questions tagged .