0

It seems that a flow is designed to run linearly but I would like to create a flow using the flow builder that runs multiple actions in parallel. Is this possible and if not, is there a good workaround?

3
  • try using queueable apex or batch context
    – Abhijith E
    Mar 19 '20 at 7:47
  • 3
    A transaction in Salesforce always flows linearly, including Apex, Flows, Workflow Rules, etc. There's no opportunity for parallel tasks in a single transaction, and that includes flows. What would be your use case?
    – sfdcfox
    Mar 19 '20 at 8:01
  • My use case is that I need to do some callouts and I also need to start a subflow with a pause element that will await platform events that are published when data is returned from each of the callouts.
    – user73893
    Mar 19 '20 at 9:04
3

As @sfdcfox said in his comment, you can't execute anything from within a transaction in Salesforce in parallel - a transaction (a synchronous or asynchronous request execution on your org) is single-threaded and there's no mechanism for creating additional threads.

The only opportunity you have to execute things in parallel is to initiate multiple synchronous or asynchronous transactions from outside the org (or for the asynchronous transaction side of things, from an existing transaction within the org).

One way to do this without the need to use any extra server infrastructure is via JavaScript from the UI using (unbuffered) Visualforce remoting or carefully orchestrated imperative Apex calls from LWC/controller invocations from Aura, since browser technology supports multiple parallel AJAX calls to a given host (your Salesforce org).

Take a look at this answer if you are interested in the LWC approach.

Use of multiple Queueables and/or batches may also give you something similar.

Implementing continuation once all the concurrent executions are finished can be somewhat fiddly too, but less so from the client-side perspective where the client is better able to keep track of outstanding transactions that relate to the one over-all process.

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.