SFDC: Passing Complex Variables Into Invocable Methods
Sometimes you have to pass complex variables (or even whole records) to invocable methods. Maybe you are passing a list of ID’s and Names or something else, but a simple list of ID’s doesn’t always cut it. In the example below I am passing a BillId (think record ID) and a Boolean together. The Boolean tells me if the specific Bill in question was allowed to be updated or not. I pass those values into two other classes I am using in a batch class elsewhere to calculate costs for Bills. However, I wanted to also create an invocable function to run the classes for a specific bill when a user clicks a button, so an invocable method was the best option!
public class Ventas_Inv_Calc_Frac_Fiscal {
@InvocableMethod(label='Calculate Fractional and Fiscal Records' description='Calculate the Fractional Positions and the Fiscal Snapshots for a given Bill Id')
public static void calculateFractionalandFiscal(FlowInputs [] request) {
String response = 'FALSE';
Ventas_Calculate_Frac_Pos_Bill fractionalCalculator = new Ventas_Calculate_Frac_Pos_Bill();
Ventas_Populate_Fiscal_Snapshots fiscalCalculator = new Ventas_Populate_Fiscal_Snapshots();
boolean fractionalPositionSucess = fractionalCalculator.calculateFractionalPositions(request[0].BillId, request[0].isNoteLocked);
if(fractionalPositionSucess){
boolean fiscalSnapshotSuccess = fiscalCalculator.populateFiscalSnapshot(request[0].BillId, request[0].isNoteLocked);
}
}
public class FlowInputs{
@InvocableVariable
public Id BillId;
@InvocableVariable
public Boolean isNoteLocked;
}
}