1

I'm evaluating Mitch Spano's trigger framework that includes the ability to invoke Flows alongside Apex actions (with neat features for ordering, bypassing, etc).

With record-triggered flows, you write the flow as if it's dealing with a single record at a time, and Salesforce handles bulkification of SOQL and DML for you. I'd like to know if that still holds true when I use this framework.

I found the section of code in the trigger framework that invokes Flows. It uses Invocable Actions like this:

public virtual List<Invocable.Action.Result> invokeAction(
  String flowApiName,
  List<Map<String, Object>> inputs
) {
  Invocable.Action action = Invocable.Action.createCustomAction(
    TriggerActionConstants.FLOW_STRING, // "Flow"
    flowApiName // e.g. "My_Flow"
  );
  action.setInvocations(inputs);
  return action.invoke();
}

Based on context, I can see that inputs is a List<Map<String, Object>> that might look something like this (if it were a JSON string):

[
  {
    "record": { "Id": "001AA00001AbcdeAAA", "Name": "Alphabet" }
    "recordPrior": { "Id": "001AA00001AbcdeAAA", "Name": "Google" }
  },
  {
    "record": { "Id": "001AA00001ZyxwvAAA", "Name": "Meta" }
    "recordPrior": { "Id": "001AA00001ZyxwvAAA", "Name": "Facebook" }
  },
]

Documentation on Invocable.Action is sparse, to say the least. So as an example: if my flow includes a single query for more data, and I perform a bulk update on 100+ records, will I incur the "Too many SOQL queries" error (given a governor limit of 100 SOQL queries per transaction)?

2 Answers 2

1

This is covered in Flow Bulkification in Transactions, albeit indirectly. There's a note with two bullet points:

  • Unlike Apex actions, legacy Apex actions aren’t bulkified.

The older Process.Plugin is not bulkified, which we can verify on its documentation:

The interface doesn’t support Blob, Collection, sObject, and Time data types, and it doesn’t support bulk operations. Once you implement the interface on a class, the class can be referenced only from flows.

So, be careful if you decide to use an Apex Action (Legacy). They can fail in bulk.

The second bullet notes:

Although Apex actions are bulkified, the flow has no way of knowing what the invoked methods’ operations are. If you want those operations to also be bulkified, make sure the code follows bulkification best practices.

However, you are righteous in your confusion. The InvocableMethod page implies that bulkification is supported:

A list of a primitive data type or a list of lists of a primitive data type – the generic Object type isn’t supported.

Etc.

The list types are the bulkification, and you need a list of lists to support Flow's Collection Variables. This has also been answered in other questions on our network, but I do agree it would be nice if the documentation was clearer on the subject.

2
  • This is helpful. To be 100% clear, this question is driving at the behavior when Apex calls Flow, not when Flow calls Apex. So the InvocableMethod docs probably have a limited relevancy. That said, I'll grant that if bulkification is explicitly supported from Flow to Apex (which, to your point, it is), then we can probably go out on a limb and pre-suppose that the reverse should also be true, even if it's not explicit. Commented Apr 14, 2023 at 13:19
  • 1
    @MatthewSouther The "Flow Bulkification in Transactions" applies to all transactions, even Apex. This answer attempts to demonstrate that the bulkification happens in both directions.
    – sfdcfox
    Commented Apr 14, 2023 at 20:21
1

Well, I tested this out by:

  • Creating a flow that queries for a specific account and then creates a note on that account, whenever an account is updated
  • Hooking my flow up to the trigger framework
  • Using Workbench to update 150 accounts at once

150 new notes were created, and no errors were thrown. I would have expected at least a "Too many DML statements" error.

Invocable.Action is pretty spiffy! If only it were better documented...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .