Cleaning up old Flow versions
Delete the older versions of a package's Flows before each install, keep the newest ones, and choose whether the flow interviews that still use them are deleted too.
Every deployment of a changed Flow adds a version in the target org. Old versions pile up toward Salesforce's 50-version limit, and they can block later deletes of the fields they reference. Set flowVersionCleanup on a source or diff package and sfp deletes the older versions of the package's Flows on every install, with no pre-deployment script.
| Attribute | Type | Description | Package Types Applicable |
|---|---|---|---|
| flowVersionCleanup.keepVersions | integer, at least 1 | How many of the newest versions of each Flow to keep. The active version is always kept as well, even when it is older. |
|
| flowVersionCleanup.deleteInterviews | boolean, default false | Also delete the paused and failed flow interviews of the versions being removed, then delete those versions. Needs the Manage Flow permission. |
|
{
"packageDirectories": [
{
"path": "src/order-management",
"package": "order-management",
"versionNumber": "2.0.10.NEXT",
"type": "source",
"flowVersionCleanup": {
"keepVersions": 5,
"deleteInterviews": false
}
}
]
}How it works
The cleanup runs before the metadata deployment, for the package's Flows that already exist in the org. Flows in pre-destructive/ or post-destructive/ are left to Flow deletion. A folded Flow version cleanup log group shows a table with one row per Flow: how many versions were kept and deleted, and the result.
Salesforce refuses to delete a version that a paused or failed flow interview still uses. sfp checks for those interviews first:
- Without
deleteInterviews, a version that interviews still use is kept and the other old versions are deleted. A warning names each kept version, its interview count and the date of its oldest interview, with codeFLOW_VERSION_IN_USE, and says how to clear them. - With
deleteInterviews: true, sfp deletes the paused and failed interviews of the versions it removes, then the versions. Only a version that a running interview uses is kept, and the next install tries it again.
Deleting a flow interview drops the work it was waiting to do, such as a paused approval or a scheduled step. Interviews of the active version and of the kept versions are never deleted, and neither are running interviews. Turn deleteInterviews on only for Flows whose paused work can be discarded.
The cleanup never fails the install. A missing Manage Flow permission (code FLOW_INTERVIEW_DELETE_FORBIDDEN or FLOW_DELETE_FORBIDDEN) or any other error is logged as a warning for that Flow, and the install continues.
Check-only deployments and dry-run installs change nothing. They log what the cleanup would delete, and which versions it would keep because interviews use them, so a validation shows the outcome before a release.
From the command line
sfp org flow cleanup applies the same rules to one Flow. --keep <n> keeps the newest n versions and the active one; without it, every inactive version is deleted. Unlike the install, the command stops with exit code 3 and deletes nothing when interviews still use a version, unless --delete-interviews is set. --dry-run reports the outcome as a warning with exit code 0, and a missing Manage Flow permission exits with code 4.