I'm using a very basic Apex Invocable Class from UnofficalSf to create SOQL queries from Flow and trying to see if there is any way I can pass one of the flow variables, such as {!vaname}
or even better something like {$Record.Name}
into this class without having to blow up the Apex Class. So some method of escape characters to use in the SOQL or small change to the Apex that might work?
Right now the Invocable receives the entire statement as a quoted string such as: SELECT Id from Account WHERE Name = {!vaname}
instead of SELECT Id from Account WHERE Name = Dell Computers
Apex Class
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 = Database.query(input.query);
// Return output
OutputParameters output = new OutputParameters();
output.records = records;
return output;
}
/**
* Wrapper class for input parameters
*/
global class InputParameters {
@InvocableVariable(required=true)
global String query;
}
/**
* Wrapper class for output parameters
*/
global class OutputParameters {
@InvocableVariable
global List<SObject> records;
}
}