[SalesForce] How to bulkify headless flow

I have access to the headless flow pilot and I have a process I would like to bulkify. Basically a Lead could be Opted in, in which case we need to make some fields true, or opted out, marking the same fields false.

I use a flow trigger to pass the Lead Id to an SObject Variable, then Fast Lookup to add these to a Collection. Then using the Collection loop through and assign true/false as required. The DML happens outside of the loop.

The above works fine for under 100 records, 100 or over it fails on too many SOQL queries…has anyone else truly bulkified a headless flow yet and what approach did you use?

Flow setup image

Best Answer

Figured this out! Below is the flow trigger equivalent of the trigger creating a list and passing to the method...I've not found this documented anywhere so hope this helps other.

In your flow first you need a SObject Variable (my example is{!LeadInputVar}) . The flow trigger will set the id of the record here. Then create a Collection (my example is {!LeadCollection}).

Now in the flow trigger check the "Set Flow Variables" box to true and assign {!this} to your Sobject Variable:

enter image description here

enter image description here

Now in your flow your first element should be an assignment, assigning the SObject Variable to the Collection:

enter image description here

Now loop through your collection: enter image description here

This is how my bulkified flow now looks: enter image description here