I am sure this is a simple fix but I can not figure out why my test class can not see my comparable class. The error I am getting is invalid type: CaseInfo
. Why would this be happening? I am following this example https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_comparable.htm . I was thinking that I have to instantiate the wrapper class in the test method but the example doesn't have the wrapper class instantiated. Is this example missing anything?
Apex Comparable:
global with sharing class viewAllCaseCommentsActivitiesController {
global class CaseInfo implements Comparable{
public Task taskData {get;set;}
public Case caseNumber {get;set;}
public caseInfo(Case caseNumber, Task taskData){
this.caseNumber = caseNumber;
this.taskData = taskData;
}
global Integer compareTo(Object compareTo)
{
CaseInfo caseinfo = (CaseInfo)compareTo;
Integer returnValue = 0;
if (taskData.Date_Activity_Logged__c < caseinfo.taskData.Date_Activity_Logged__c) {
returnValue = 1;
} else if (taskData.Date_Activity_Logged__c > caseinfo.taskData.Date_Activity_Logged__c) {
returnValue = -1;
}
return returnValue;
}
}
public viewAllCaseCommentsActivitiesController() {
....
}
}
Test Class:
static testmethod void test1() {
Account a = new Account(Name = 'Test Account Name');
insert a;
Case c = new Case(Account = a);
insert c;
Task t = new Task(Private__c = FALSE, WhatId = c.Id);
insert t;
Account a2 = new Account(Name = 'Test Account Name');
insert a2;
Case c2 = new Case(Account = a);
insert c2;
CaseComment cc = new CaseComment(ParentId = c2.Id);
insert cc;
CaseComment cc2 = new CaseComment(ParentId = c2.Id);
insert cc2;
Task t2 = new Task(Private__c = FALSE, WhatId = c.Id);
insert t2;
List<CaseInfo> caseList = new List<CaseInfo>(); //error here
caseList.add(new CaseInfo(c, t));
caseList.add(new CaseInfo(c2, t));
caseList.add(new CaseInfo(c2, t2));
// Sort using the custom compareTo() method
caseList.sort();
// Write list contents to the debug log
System.debug(caseList);
}