We have an Invocable Apex Class to do SOQL which uses generic SObject in flow but returns an error the same if trying to use that Sobject for the Custom Metadata getAll method.
global with sharing class CreateSobjectInvoc {
@InvocableMethod(label='Executes a SOQL query' category='Data')
global static List<OutputParameters> bulkInvoke(
List<InputParameters> inputs
) {
List<OutputParameters> outputs = new List<OutputParameters>();
for (InputParameters input : inputs) {
outputs.add(invoke(input));
}
return outputs;
}
private static OutputParameters invoke(InputParameters input) {
List<SObject> records = SObject.getAll().values()
// Return output
OutputParameters output = new OutputParameters();
output.records = records;
return output;
}
global class InputParameters {
@InvocableVariable(required=false)
global String query;
}
global class OutputParameters {
@InvocableVariable
global List<SObject> records;
}
}
Error
Method does not exist or incorrect signature: void getAll() from the type SObject
The class works fine if I supply a specific Custom Metadata Object name instead but that would require a separate class for each Custom Metadata object. Is there a way to acheive this without doing that?