I have a custom data type, 'CaseOutput' that returns a list of case records. The below system.debug returns the first CaseOutput element.
system.debug(CaseEinsteinHandler.getCaseStatus(listInput)[0]);
yields
USER_DEBUG [20]|DEBUG|CaseOutput:[cases=(Case:{CaseNumber=00101778, Status=Open, Id=5007A000004gm9wQAA})]
I would like to access CaseNumber to use for my System.assertEquals comparison. How can I extract that value?
Apex Class
public with sharing class CaseEinsteinHandler {
/**************************************/
public class CaseOutput {
@InvocableVariable(required=true)
public List <Case> cases;
}
public class CaseInput {
@InvocableVariable(required=true)
public String sEmailAddress;
}
/**************************************/
@InvocableMethod(label='Get Case Status')
public static List<CaseOutput> getCaseStatus(List<CaseInput> caseInputs) {
// Build a list of case status values for the output
List<CaseOutput> caseOutputs = new List<CaseOutput>();
// Get the case objects (records) from the set of contact email addresses
if (caseInputs.size() > 0 && caseInputs[0].sEmailAddress != null) {
List<Case> allCases =
[SELECT CaseNumber, Status, Subject
FROM Case WHERE ContactEmail = :caseInputs[0].sEmailAddress AND Status In ('Open', 'In Progress', 'Escalated')];
CaseOutput caseOutput = new CaseOutput();
caseOutput.cases = allCases;
caseOutputs.add(caseOutput);
}
return caseOutputs;
}
}
Unit Test
@isTest private class CaseEinsteinHandlerTest {
@testSetup
static void setupTestData() {
Account a = new Account(Name = 'Test Account');
insert a;
Contact ct = new Contact(LastName = 'TestContact', AccountId = a.id, Email = 'test@sf.com');
insert ct;
Case c = new Case(Status='Open', Origin = 'Email', ContactId = ct.Id);
insert c;
}
static TestMethod void test_searchCase() {
CaseEinsteinHandler.CaseInput input = new CaseEinsteinHandler.CaseInput();
input.sEmailAddress = 'test@sf.com';
List<CaseEinsteinHandler.CaseInput> listInput = new List<CaseEinsteinHandler.CaseInput>();
listInput.add(input);
// need to drill down
system.debug(CaseEinsteinHandler.getCaseStatus(listInput)[0]);
// System.assertEquals();
}
}