Enqueue Flow (Queueable)
Overview
The Enqueue Flow (Queueable) component lets you run an Autolaunched Flow asynchronously via Queueable Apex.
This is ideal for large data sets or long-running operations that might exceed Flow limits when executed synchronously.
You provide the Flow API Name and input parameters; the component enqueues a background job and returns the AsyncApexJob Id.
Notes: This action does not wait for the Flow to finish. It returns immediately with a job Id you can track.
Inputs
-
flowName (Required)
The API Name of the Autolaunched Flow to run (e.g.,Mass_Update_Opportunities,My_Autolaunched_Flow). -
parameters (Required)
A collection of key/value pairs to pass as inputs to the Flow, usingPlinqx.RequestKeyValuePair.- Each pair should match an input variable in the target Flow (names are case-sensitive to the Flow variable API names).
- Typical structure is a
key(the Flow variable name) and avalue(stringified value). - Provide one pair per Flow input you need to set.
Ensure the target Flow variables are Available for input.
Outputs
- jobId
The Id of the enqueued AsyncApexJob. Use it to monitor job status (e.g., with Setup → Apex Jobs or SOQL onAsyncApexJob).
How it Works (Queueable Runtime)
- The invocable engine enqueues a Queueable job with your
flowNameandparameters. - The Queueable job:
- Creates a Flow interview for
flowNameand starts it. - Reads a Flow output variable named
valueOut(type:List<Plinqx.RequestKeyValuePair>). - Looks for two control keys in that output:
done— Boolean ("true"/"false")error— Boolean ("true"/"false")
- Behavior:
- If
done=falseanderror=false: the job re-queues itself with the remaining key/values fromvalueOut(after removing thedoneflag). This lets you iterate work over multiple queueable executions with fresh limits each time. - If
done=trueorerror=true: processing stops (no further re-queue). - If
doneis missing: an exception is thrown (Flow response key 'done' not found).
- If
- Creates a Flow interview for
Flow Contract (Required in the Target Flow)
Your Autolaunched Flow must implement the following:
-
Input variables
Create input variables that match the keys you pass inparameters(case-sensitive). Mark them Available for input. -
Output variable
Create a single Flow output variable:- API Name:
valueOut - Data Type: Apex-Defined
- Apex Class:
Plinqx.RequestKeyValuePair - Collection: Yes (this must be a collection of key/value pairs)
- Mark Available for output
- API Name:
-
Control flags in
valueOut
On every run, populatevalueOutwith at least these entries:done→"true"or"false"(string Boolean)error→"true"or"false"(string Boolean)
Rules:
- If you want the Queueable to run again (continue work), set
done = "false"anderror = "false", and include any state you want to carry into the next run as additional key/value pairs invalueOut. - If processing is complete (or has failed), set
done = "true"(orerror = "true"). The Queueable will not re-enqueue.
The Queueable removes the
donekey before re-queuing and passes the rest ofvalueOutback as the nextparameters.
Stateful Iteration Pattern (Example)
Use this pattern to chunk large work across multiple queueable executions:
First call (from your Flow/Process/Action):
parameters:Offset = 0PageSize = 200
Inside the target Flow (run #1):
- Query/process records 0–199.
- Compute next state.
- Set
valueOut:done = "false"(more work remains)error = "false"Offset = 200PageSize = 200
Queueable re-enqueues with new parameters → Offset=200.
Inside the target Flow (run #2):
- Process 200–399 …
- When finished:
done = "true"error = "false"
Queueable stops (no further jobs).
Example — Enqueue a Bulk Update Flow
Goal: Enqueue an Autolaunched Flow Mass_Opportunity_Update with inputs for TargetStage and RecordIds. The Flow also outputs valueOut with the control flags.
Inputs
flowName:Mass_Opportunity_Updateparameters:key=TargetStage,value=Closed Wonkey=RecordIds,value=006xx00000AAAAA,006xx00000BBBBB(comma-delimited if your Flow expects a string list)
Flow must set (in valueOut on completion of a chunk)
done = "true"(or"false"to continue)error = "false"(or"true"if you want to abort the chain)- Any additional state keys you need to pass to the next run.
Output (from this invocable)
jobId:707xx0000123ABC(use this to track in Setup → Apex Jobs)
Best Practices
- Autolaunched & Active: Target Flow must be Autolaunched and Active.
- Implement the contract: Always return
valueOutwithdoneanderroron every run. Missingdonewill throw an exception error. - Use strings for values: The key/value pairs are strings; convert inside your Flow as needed.
- Carry state forward: Place your next-run state in
valueOut(e.g., offsets, cursor ids). - Chunk work: Process in small batches per run so each job stays within limits.
- Idempotency: If re-enqueuing is possible, add guards in your Flow (e.g., checkpoint keys) to avoid double-processing.
- Monitoring: Use the Apex Jobs page and Flow error results to monitor failures/retries.
- Error termination: Set
error = "true"to stop re-queuing when an unrecoverable error occurs; consider also returning anerrorMessagekey for observability.
Troubleshooting
-
“Flow response key 'done' not found.”
Your Flow did not includedoneinvalueOut. EnsurevalueOutis an Apex-Defined collection ofPlinqx.RequestKeyValuePairand includesdone/error. -
Flow didn’t run
Verify the Flow API name, that it’s Autolaunched, Active, and its variables are Available for input/output as required. -
Input mapping issues
Check parameter keys for typos; align types (stringify as needed). -
Governor limits inside the Flow
Even though execution is async, your Flow must still handle data volumes efficiently (bulkify queries/DML where applicable and use the iteration pattern above).
Example Scenario — Enqueue a Bulk Update Flow
Scenario Overview:
A Salesforce org needs to update thousands of Opportunities to a new Stage. Running this in a single synchronous Flow risks hitting limits. By using Enqueue Flow (Queueable), the work can be split into manageable chunks and processed asynchronously.
Implementation with Enqueue Flow (Queueable):
Flow Setup for Bulk Update:
Create an Autolaunched Flow named Mass_Opportunity_Update. This Flow accepts input parameters for the target Stage, as well as state variables such as Offset and PageSize that control batch processing.
Adding Enqueue Flow (Queueable) Component:
In your parent Flow or process, add the Enqueue Flow (Queueable) component and configure it with the following:
-
flowName = Mass_Opportunity_Update -
parameters:-
TargetStage = Closed Won -
Offset = 0 -
PageSize = 200
-
First Execution:
The Queueable job launches Mass_Opportunity_Update. Inside the Flow:
-
Records 0–199 are queried and updated.
-
The Flow sets its output variable
valueOutto include:-
done = "false" -
error = "false" -
Offset = 200 -
PageSize = 200
-
Iterating with Queueable:
Because done = false, the Queueable automatically re-enqueues itself with the new state (Offset=200). The Flow runs again, processing records 200–399. This pattern continues, with each run handling the next batch of records.
Final Execution:
When no more records remain, the Flow sets valueOut:
-
done = "true" -
error = "false"
The Queueable stops, completing the bulk update process.
Utilizing the Output:
The component immediately returns a jobId (e.g., 707xx0000123ABC). You can track this job in Setup → Apex Jobs or via SOQL queries on AsyncApexJob.
