2

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

5

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

  • Unless I'm missing something doesn't this just create a single element collection every time your Flow Trigger runs? Is there all any reason why you decided not to do this using a standard Workflow Rule and Field Updates? – Alex Tennant Oct 28 '14 at 10:19
  • 1
    There are something like 25 fields updates which requires 3 workflow rules as there can only be 10 fields update in a workflow rule. Then there are 3 more to uncheck the boxes on an opt out, then the same again for Contacts. I should be able to do this all in one flow without having to maintain all those workflow rules. – Girbot Oct 28 '14 at 10:23
  • @Girbot, essentially you eliminated the Fast Lookup at the start of your flow by passing in {!this}? I can see how if you were updating a lot of records (e.g. file import or something else) all those look ups can add up. – Doug Ayers Oct 29 '14 at 0:55
  • Yes in conjunction with the assignment element which adds the SObject variable to the Lead Collection that gets looped through. – Girbot Oct 29 '14 at 9:50
  • As @AlexTennant suggests, I think the solution is slightly over-engineered. It would work equally well without the assignment to the collection and the loop, as Salesforce bulkifies the execution of the flow for you. Removing the Fast Lookup was what resolved your issue, as it doesn't work in bulk at present. I've described my understanding of the issue and bulkification of flows here: tquila.com/blog/2015/03/09/bulkify-lightning-process-builder. The blog talks about process builder, but flow triggers appear to function identically. – James Mar 10 '15 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.