Skip to main content
Version: 1

Enqueue Flow (Queueable)

  • Category

    • Flow
    • Asynchronous
    • Queueable
    • Performance
  • Flow Icon

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.

info

Notes: This action does not wait for the Flow to finish. It returns immediately with a job Id you can track.


Inputs

  1. flowName (Required)
    The API Name of the Autolaunched Flow to run (e.g., Mass_Update_Opportunities, My_Autolaunched_Flow).

  2. parameters (Required)
    A collection of key/value pairs to pass as inputs to the Flow, using Plinqx.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 a value (stringified value).
    • Provide one pair per Flow input you need to set.

Ensure the target Flow variables are Available for input.


Outputs

  1. jobId
    The Id of the enqueued AsyncApexJob. Use it to monitor job status (e.g., with Setup → Apex Jobs or SOQL on AsyncApexJob).

How it Works (Queueable Runtime)

  • The invocable engine enqueues a Queueable job with your flowName and parameters.
  • The Queueable job:
    1. Creates a Flow interview for flowName and starts it.
    2. Reads a Flow output variable named valueOut (type: List<Plinqx.RequestKeyValuePair>).
    3. Looks for two control keys in that output:
      • done — Boolean ("true" / "false")
      • error — Boolean ("true" / "false")
    4. Behavior:
      • If done = false and error = false: the job re-queues itself with the remaining key/values from valueOut (after removing the done flag). This lets you iterate work over multiple queueable executions with fresh limits each time.
      • If done = true or error = true: processing stops (no further re-queue).
      • If done is missing: an exception is thrown (Flow response key 'done' not found).

Flow Contract (Required in the Target Flow)

Your Autolaunched Flow must implement the following:

  1. Input variables
    Create input variables that match the keys you pass in parameters (case-sensitive). Mark them Available for input.

  2. 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
  3. Control flags in valueOut
    On every run, populate valueOut with 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" and error = "false", and include any state you want to carry into the next run as additional key/value pairs in valueOut.
    • If processing is complete (or has failed), set done = "true" (or error = "true"). The Queueable will not re-enqueue.

The Queueable removes the done key before re-queuing and passes the rest of valueOut back as the next parameters.


Stateful Iteration Pattern (Example)

Use this pattern to chunk large work across multiple queueable executions:

First call (from your Flow/Process/Action):

  • parameters:
    • Offset = 0
    • PageSize = 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 = 200
    • PageSize = 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_Update
  • parameters:
    • key=TargetStage, value=Closed Won
    • key=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 valueOut with done and error on every run. Missing done will 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 an errorMessage key for observability.

Troubleshooting

  • “Flow response key 'done' not found.”
    Your Flow did not include done in valueOut. Ensure valueOut is an Apex-Defined collection of Plinqx.RequestKeyValuePair and includes done/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 valueOut to 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.