Skip to content

hardis:org:purge:flow

Description

Purges old or unwanted Flow versions from a Salesforce org, with an option to delete related Flow Interviews.

This command helps maintain a clean and performant Salesforce org by removing obsolete Flow versions. Over time, multiple versions of Flows can accumulate, consuming storage and potentially impacting performance. This tool provides a controlled way to clean up these versions.

Key functionalities:

  • Targeted Flow Selection: Allows you to filter Flow versions to delete by name (--name) and status (--status, e.g., Obsolete, Draft, Inactive).
  • Flow Interview Deletion: If a Flow version cannot be deleted due to active Flow Interviews, the --delete-flow-interviews flag (or interactive prompt) allows you to delete these interviews first, then retry the Flow version deletion.
  • Confirmation Prompt: In interactive mode, it prompts for confirmation before proceeding with the deletion of Flow versions and Flow Interviews.
  • Partial Success Handling: The --allowpurgefailure flag (default true) allows the command to continue even if some deletions fail, reporting the errors.
Technical explanations

The command's technical implementation involves:

  • SOQL Queries (Tooling API): It queries the Flow object (using the Tooling API) to list Flow versions based on the provided filters (name, status, manageable state).
  • Bulk Deletion (Tooling API): It uses bulkDeleteTooling to perform mass deletions of Flow versions. If deletion fails due to active interviews, it extracts the interview IDs.
  • Flow Interview Management: If delete-flow-interviews is enabled, it queries FlowInterview objects, performs bulk deletion of the identified interviews using bulkDelete, and then retries the Flow version deletion.
  • Interactive Prompts: Uses the prompts library to interact with the user for selecting Flows, statuses, and confirming deletion actions.
  • Error Reporting: Logs detailed error messages for failed deletions, including the specific reasons.
  • Command-Line Execution: Uses execSfdxJson to execute Salesforce CLI commands for querying Flow data.

Agent Mode

Supports non-interactive execution with --agent:

sf hardis:org:purge:flow --agent --target-org myorg@example.com

In agent mode:

  • All interactive prompts and confirmations are skipped.
  • If --status is not provided, defaults to Obsolete.
  • If --name is not provided, all matching Flows are targeted.
  • Flow version and Flow Interview deletions proceed without confirmation.

Screenshots

Pick the statuses of the Flow versions to delete

Pick the statuses of the Flow versions to delete

Draft, inactive and obsolete Flow versions deleted from the Helios test org, with the list before and the result after

Draft, inactive and obsolete Flow versions deleted from the Helios test org, with the list before and the result after

  • (1) The versions selected, to check before confirming
  • (2) The deletion status of each version

Reports

The command writes these reports in the hardis-report folder of the project: a CSV file, and its Excel copy (XLSX) in the xls sub-folder.

Flow versions to delete

One row per Flow version selected for deletion, so you can check the list before confirming.

Files: org-purge-flow-to-delete-*.csv, xls/org-purge-flow-to-delete-*.xlsx

Flow versions to delete report in Excel

Flow interviews to delete

One row per Flow interview that blocks the deletion of a Flow version, with its name, label, status and creator; written only when there are more than 20 rows.

Files: flow-interviews-to-delete-*.csv, xls/flow-interviews-to-delete-*.xlsx

Flow interviews to delete report in Excel

Deleted records

One row per Flow version or Flow interview the command tried to delete, with its deletion status and error if any.

Files: org-purge-flow-deleted-*.csv, xls/org-purge-flow-deleted-*.xlsx

Deleted records report in Excel

Parameters

Name Type Description Default Required Options
agent boolean Run in non-interactive mode for agents and automation
allowpurgefailure
-f
boolean Allows purges to fail without exiting with 1. Use --no-allowpurgefailure to disable
debug
-d
boolean Activate debug mode (more logs)
delete-flow-interviews
-w
boolean If the presence of Flow interviews prevent to delete flows versions, delete them before retrying to delete flow versions
flags-dir option Import flag values from a directory.
instanceurl
-r
option URL of org instance https://login.salesforce.com
json boolean Format output as json.
name
-n
option Filter according to Name criteria
prompt
-z
boolean Prompt for confirmation (true by default, use --no-prompt to skip)
skipauth boolean Skip authentication check when a default username is required
status
-s
option Filter according to Status criteria
target-org
-o
option Username or alias of the target org. Not required if the target-org configuration variable is already set. true
websocket option Websocket host:port for VsCode SFDX Hardis UI integration

Examples

$ sf hardis:org:purge:flow
$ sf hardis:org:purge:flow --target-org nicolas.vuillamy@gmail.com --no-prompt --delete-flow-interviews
$ sf hardis:org:purge:flow --target-org nicolas.vuillamy@gmail.com --status "Obsolete,Draft,InvalidDraft" --name TestFlow
$ sf hardis:org:purge:flow --agent

Comments