Skip to main content

Sweep Order of Execution in Salesforce

Understand how Sweep handles the order of execution when records are inserted, updated, or deleted

Tess Geri avatar
Written by Tess Geri
Updated over a year ago

When a record is saved in Salesforce with an insert, update, or delete action, Sweep follows a specific order of execution. These events are managed differently depending on the type of action (insert, update, delete) and the context (synchronous vs. asynchronous). Below is a detailed breakdown of Sweep's order of execution, reflecting how automations are triggered and processed.

After Insert

On insert, Sweep runs in an ‘after insert’ context where the records already have an id, in order to support referencing related records.

  1. Run Dedupe and Matching automations marked as ‘On Create’ on all records coming in the trigger.

  2. Loop trigger records, for each record:

    1. Run ‘On Create’ automations.

    2. If a record has a record type that is mapped to a Sweep Funnel -

      1. Run automations where the trigger is related to funnel - On Step Enter

      2. Check for automatic progress gates

      3. Run automations where the trigger is related to funnel - On Step Exit

  3. Call batch job to run Sweep Rollups where the child object equals the triggering object. async

  4. Perform an update call on all records in the trigger’s context (do not call Sweep again).

  5. Post trigger -

    1. Update & delete records collected by dedupe & matching async

    2. Call jobs to run all async actions collected in the trigger async

Before Update

  1. Run Dedupe and Matching automations marked as ‘On Update’ on all records coming in the trigger.

  2. Loop trigger records, for each record:

    1. Run ‘On Update’ automations.

    2. If a record has a record type that is mapped to a Sweep Funnel -

      1. Run automations where the trigger is related to funnel - On Field Update

      2. Run automations where the trigger is related to the funnel - On Step Enter

      3. Check for automatic progress gates

    3. Run automations where the trigger is related to funnel - On Step ExIf not, run ‘On Field Update’ automations.

  3. Call batch job to run Sweep Rollups where the child object equals the triggering object. async

After Update

  1. Post trigger -

    1. Update & delete records collected by dedupe & matching async

    2. Call jobs to run all async actions collected in the trigger async

After Delete

  1. Call batch job to run Sweep Rollups where the child object equals the triggering object async.

Synchronous vs. Asynchronous Actions in Sweep:

  • Synchronous Actions:

    • These actions are performed immediately within the same transaction context, such as:

      • Matching and Deduplication

      • Assignment Rules

      • Update Record (for the record that triggered the automation)

  • Asynchronous Actions:

    • Actions that are deferred to be processed later to avoid hitting Salesforce governor limits include:

      • Create Record

      • Update Related Records

      • Send Email

      • Slack Notifications (e.g., creating a channel, adding members)

      • Convert Lead

By organizing these actions asynchronously, Sweep helps optimize overall performance and efficiency, reducing the risk of reaching Salesforce limits like CPU timeouts.

Did this answer your question?