Salesforce Developer Builds Tool To Clean Up Obsolete Flow Versions
A developer created a tool to delete unused flow versions, making it easier to manage and clean up Salesforce orgs. This tool uses the Tooling API to safely remove obsolete flow versions.
Original reporting · salesforce.com
Original: “7 Architectural Lessons From Building With the Tooling API”
Read “7 Architectural Lessons From Building With the Tooling API” at Salesforce Blog →
How this was written. GDS wrote this article with a language model from Salesforce Blog’s reporting (model: @cf/meta/llama-3.3-70b-instruct-fp8-fast); it describes that reporting rather than adding to it. The original, linked above, is the full story.
Key points from Salesforce Blog’s report
- The Flow Version Cleaner tool uses the Tooling API to safely delete obsolete flow versions in Salesforce orgs.
- Defining requirements before designing the tool is crucial to ensure it meets the necessary conditions and does not interrupt automation.
- Understanding the API object model and system boundary dependencies is essential for successful integration and execution.
- Authentication and authorization must be carefully considered to ensure the tool has the necessary permissions and can execute successfully.
- The Tooling API provides fine-grained access to individual flow versions and supports deleting each eligible version independently at runtime.
Salesforce orgs can accumulate hundreds of flows and thousands of flow versions, making cleanup a time-consuming task. To address this issue, a developer built a Flow Version Cleaner tool that utilizes the Tooling API to prune obsolete flow versions.
The tool's development was not without challenges, and the developer learned several key lessons along the way. One major lesson was the importance of defining requirements before designing the tool, as initial assumptions may not hold up during runtime.
The Flow Version Cleaner has three main requirements: it must never delete the active flow version, retain flow versions newer than the active one, and keep a configurable number of recent inactive flow versions. These requirements ensure that automation is not interrupted and provide a fallback in case issues arise with the active version.
When choosing an API for the tool, the developer compared the Apex Metadata namespace, Metadata API, and Tooling API. The Tooling API was ultimately selected due to its ability to delete specific flow versions and support retention rules at runtime.
Authentication and authorization were also crucial considerations in the tool's development. The developer learned that using a running user's session ID was not a suitable solution, as it could lead to permission issues and failed executions. Instead, Named Credentials were used to separate authentication parameters from the Apex code.
Understanding the API object model was another essential lesson. The Tooling API exposes a complex structure that is not immediately apparent from the Salesforce UI. For example, a flow consists of multiple components, including a flow definition, flow record, and flow interview, which must be accessed and manipulated separately.
The developer also encountered system boundary dependencies, where integration dependencies emerged between different APIs and data models. To delete flow versions, the tool must first delete associated flow interviews, which requires using the Composite REST API and then the Tooling API.
Questions and answers
What is the purpose of the Flow Version Cleaner tool?
The Flow Version Cleaner tool is designed to delete obsolete flow versions in Salesforce orgs, making it easier to manage and clean up the org.
Why was the Tooling API chosen for the tool?
The Tooling API was chosen due to its ability to delete specific flow versions and support retention rules at runtime, making it the most suitable option for the tool's requirements.
What are the main requirements of the Flow Version Cleaner tool?
The tool has three main requirements: never delete the active flow version, retain flow versions newer than the active one, and keep a configurable number of recent inactive flow versions.


