Trying to get a list of cases that are equal to the cases in the variable caseInputs but i get three errors.
1.Invalid bind expression type of Integer for column of type String->its probably regarding my sql query? 2. Method does not exist or incorrect signature: void containsKey(Integer) from the type Map<String,String> 3. Method does not exist or incorrect signature: void get(Integer) from the type Map<String,String>
Never worked with maps but i guess its because ive an integer variable but iam mapping an integer and string variable?
public with sharing class Cases {
public class CaseOutput {
@InvocableVariable(required=true)
public String sCaseStatus;
}
public class CaseInput {
@InvocableVariable(required=true)
public Integer sCaseNumber;
}
@InvocableMethod(label='Get Case Status')
public static List<CaseOutput> getCaseStatus(List<CaseInput> caseInputs) {
Set<Integer> caseNumbers = new Set<Integer>();
// Get the case numbers from the input
for (CaseInput caseInput : caseInputs) {
caseNumbers.add(caseInput.sCaseNumber);
}
// Get the case objects from the set of order numbers
List<Case> cases =
[SELECT casenumber,subject, status FROM Case WHERE casenumber in :caseNumbers];
// Create a map of case numbers and case status values
Map<String, String> mapNameStatus = new Map<String, String>();
if (cases.size() > 0) {
for (Case oneCase : cases) {
mapNameStatus.put(oneCase.Subject, oneCase.Status);
}
}
// Build a list of case status values for the output
List<CaseOutput> caseOutputs = new List<CaseOutput>();
for (CaseInput caseInput : caseInputs) {
CaseOutput caseOutput = new CaseOutput();
// Do we have a status for this case number?
if (mapNameStatus.containsKey(caseInput.sCaseNumber)) {
// If so, then add the status
caseOutput.sCaseStatus = mapNameStatus.get(caseInput.sCaseNumber);
} else {
// If not, then add an unknown status value
caseOutput.sCaseStatus = 'Case not found';
}
caseOutputs.add(caseOutput);
}
return caseOutputs;
}
}