FlowApi: running in foreground vs background
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2023 09:08 AM
Hi all,
I have a Flow Designer flow where the trigger has:
- Trigger = Created or Updated
- Run Trigger = Only if not currently running
- Where to run the flow = Run flow in background (default)
When I look at Create Code Snippet, I see that the server script has two options to run in the foreground or background. Something like:
1) sn_fd.FlowAPI.getRunner().flow('flow_name').inBackground().withInputs(inputs).run();
2) sn_fd.FlowAPI.getRunner().flow('flow_name').inForeground().withInputs(inputs).run();
By default, inBackground() is commented out, so it looks like it wants me to use inForeground().
My question is this:
Would inForeground() interfere with the trigger conditions of "Where to run the flow = Run flow in background (default)"?
I want to call FlowAPI from a daily scheduled job. If the scheduled job loops through 30 or so records and calls FlowAPI to execute the flow for each record, would inForeground() cause issues like taking a long time to run?
Thanks in advance for the help 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2023 09:14 AM - edited 04-03-2023 09:15 AM
Like the comment says one is for synchronous and the other is for asynchronous. So my understanding is if you use the inForeground your code will wait for the flow to run and finish before moving on to the next line. inBackground causes the code to move on immediately to the next line and the flow will execute on its own and not hold things up.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2023 10:02 AM
Gotcha. I'm expecting a single flow execution to take days-weeks to complete (it has approval steps, so it's up to how fast the approver gets to it), so if I expect my scheduled job to trigger 30 flow executions in a few seconds, looks like inForeground() is not the way to go.