Refactoring code to merge similar operations and getting an error the SObjects I'm passing to this method are variables that do not exist.
private static List<SObject> getSObjectList(SObject salesforceObject, Set<String> filterSet, String exceptionMessage) {
List<SObject> records;
switch on salesforceObject {
when Contact {
records = [SELECT Id, Name FROM Contact WHERE Name IN :filterSet];
}
when pse__Milestone__c {
records = [SELECT Id, Milestone_ID__c, pse__Project__c, pse__Project__r.pse__Account__c, pse__Project__r.pse__Allow_Timecards_Without_Assignment__c, pse__Project__r.pse__Is_Billable__c, pse__Project__r.Apply_Burndown_Cap__c, pse__Project__r.Remaining_Hours__c, Exclude_Timecards_from_Billing__c FROM pse__Milestone__c WHERE Milestone_ID__c IN :filterSet];
}
}
if (records.size() == 0) {
notifyAdmin('TimeLoaderJira Exception', exceptionMessage);
throw new ImportException(exceptionMessage);
}
return records;
}
Getting error "Variable does not exist: Contact" from this line that invokes it:
List<Contact> resources = (List<Contact>) getSObjectList(Contact, resourceNames, 'Data imported did not contain any valid resources.');
and "Variable does not exist: pse__Milestone__c" for this one:
List<pse__Milestone__c> milestones = (List<pse__Milestone__c>) getSObjectList(pse__Milestone__c, milestonesFriendly, 'Data imported did not contain any valid milestones.');
Any thoughts about what I'm doing wrong?