0

(I believe) I want to create a Map that I need someone's advice on. I want the map to have the key be equal to a Task's CreatedDate and the Value be TWO object's values- the Task's Data and the Case's CaseNumber. This is what I have so far:

orderedTaskList1 = [SELECT (SELECT CreatedDate, Comments__c, OwnerId, Subject, Owner.Name, AccountId, WhatId, CreatedById, Account.Name FROM Tasks WHERE Private__c = FALSE AND (Status = 'Completed' OR Status = 'Closed')
                    ORDER BY CreatedDate DESC), AccountId, CaseNumber, Merchant_Number__c FROM Case WHERE AccountId = :strAccountId AND Id IN :accountIds];

        caseTaskMap = new Map<String, Task[]>();

        for(Case c : orderedTaskList1){
            caseTaskMap.put(c.CaseNumber, c.Tasks);
            listOftaskCaseTasks = c.Tasks;
            for(Task t : listOftaskCaseTasks){
                orderedTaskListCreatedDate= t.CreatedDate;
                mapOfDateAndTaskandCase = new Map<Datetime,Map<String, Task[]>>();
                mapOfDateAndTaskandCase.put(orderedTaskListCreatedDate, caseTaskMap);
        }

My issue that I am running into is that it is only bringing back ONE CreatedDate. As you can see from the example Case # 00033494 has a different created date but the date is not listed as the key:

{2017-07-13 16:28:02={
     00033490=(
           Task:{WhatId=500S0000008l5A3IAI, Id=00TS000000Ul9qEMAR, CreatedDate=2017-07-13 16:31:20, Comments__c=RESPONSE TEMPLATE, OwnerId=00580000003HZZnAAO, Subject=RE: Sandbox: - Olivia Test Case Portfolio Record Type RESPONSE TEMPLATE, CreatedById=00580000003HZZnAAO, RecordTypeId=01280000000BawwAAC}, 
           Task:{WhatId=500S0000008l5A3IAI, Id=00TS000000Ul9q8MAB, CreatedDate=2017-07-13 16:30:18, Comments__c=Olivia Test Case Portfolio Record Type SENT, OwnerId=00534000009QnEtAAK, Subject=Email: - Olivia Test Case Portfolio Record Type SENT TEMPLATE, AccountId=001S000000raQdyIAE, CreatedById=00534000009QnEtAAK, RecordTypeId=01280000000BawwAAC}, 
           Task:{WhatId=500S0000008l5A3IAI, Id=00TS000000Ul9puMAB, CreatedDate=2017-07-13 16:28:30, Comments__c=RESPONSE, OwnerId=00580000003HZZnAAO, Subject=RE: Sandbox: Olivia Test Case Portfolio Record Type RESPONSE, CreatedById=00580000003HZZnAAO, RecordTypeId=01280000000BawwAAC}, 
           Task:{WhatId=500S0000008l5A3IAI, Id=00TS000000Ul9poMAB, CreatedDate=2017-07-13 16:28:02, Comments__c=Olivia Test Case Portfolio, OwnerId=00534000009QnEtAAK, Subject=Email: Olivia Test Case Portfolio Record Type SENT, AccountId=001S000000raQdyIAE, CreatedById=00534000009QnEtAAK, RecordTypeId=01280000000BawwAAC}), 

      00033494=(
           Task:{WhatId=500S0000008lPkSIAU, Id=00TS000000UlRjlMAF, CreatedDate=2017-07-17 18:57:22, Comments__c=TEST COMMENTS, Id=00534000009ceS2AAI, Subject=RE: Sandbox: Wire In -, CreatedById=00534000009ceS2AAI})}}

The ideal scenario would be to have a map that looked something like this:

Map<TaskCreatedDate, List<AllOfTheTaskInformationAndTheCaseNumberRelatedToTheTask>>

I have looked into just putting a field on the Task object that pulls it's CaseNumber but I guess this is not a possibility yet. So other then making a junction object, any suggestions on this map?

UPDATE:

The wrapper class works great and to be able to pull out the values into a list I would like it to look something along the lines of:

<apex:repeat value="{!caseTaskMap}" var="taskTime">
    <th colspan="5" id="casenumber">{!taskTime}</th> <!--2017-07-13 16:28:02--><!--PRINTS OUT THE FIRST KEY-->
    <apex:repeat value="{!caseTaskMap[taskTime]}" var="caseInfo"> <!--PRINTING OUT THE FIRST VALUE-->
        <apex:repeat value="{!caseTaskMap[taskTime[caseInfo]]}" var="taskData">
            <apex:repeat value="{!caseTaskMap[taskTime[caseInfo[taskData]]]}" var="task">
                <tr>
                    <td>{!taskData.CaseNumber}</td>
                    <td>{!task.Subject}</td>
                </tr>
            </apex:repeat>
        </apex:repeat>
    </apex:repeat>
</apex:repeat>
2

You could use an apex wrapper class to hold the info :

    caseTaskMap = new Map<String, CaseInfo>();
    for(Case c : orderedTaskList1 ){
        for (Task t : c.Tasks) {
          caseTaskMap.put(''+t.createDate new CaseInfo(c.CaseNumber,t);
        }
     }

Wrapper class

class CaseInfo {
  String caseNumber;
  Task taskData;

  CaseInfo(String caseNumber, Task taskData) {
    this.caseNumber = caseNumber;
    this.taskData = taskData;
  }
}
  • Great suggestion. The wrapper class worked great. I will mark correct but I do have a follow up question with pulling the values out in this format. When I do a apex:repeat on these values, how would I be able to tap into the second key/value pair? I will update the question with an example of what I am talking about. – Olivia Jul 25 '17 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.