I'm trying to display a chronological list of CaseHistory records to display case edits. I have the following code:
public Map<CaseHistory,String> getHelpdeskHistory() {
List<CaseHistory> historyList = new List<CaseHistory>();
historyList = [SELECT Case.Subject , CreatedById, OldValue, NewValue, Field, CreatedDate FROM CaseHistory ORDER BY CreatedDate DESC];
Map<CaseHistory, String> mapCaseToEditor = new Map<CaseHistory,String>();
for(CaseHistory ch: historyList){
User caseEditor = new User();
caseEditor = [select Name from User where id = :ch.CreatedById];
mapCaseToEditor.put(ch, caseEditor.Name);
}
return mapCaseToEditor;
}
The CreatedById is the ID of the user who edited a case. I'm retrieving them ordered by CreatedDate, but I need to attach a name to display it on my visualforce page.
However, due to the map being unordered, I can't figure out a better way to preserve the order returned by the query. This is how I display it in the VF page:
<apex:repeat value="{!HelpdeskHistory}" var="C">
{!HelpdeskHistory[C]} edited {!C.Field}
</apex:repeat>
This works and displays the person who edited the case, but it's not in CreatedDate order. Is there any way I can attach a name to an ordered list and display it in VF?