Metadata Type: FlowDefinition
FlowDefinition is a metadata type in Salesforce that represents the description and active version number of a flow. This research paper explores the characteristics, deployment issues, and best practices associated with FlowDefinition in Salesforce.
Overview of FlowDefinition
FlowDefinition is stored in the flowDefinitions directory of the corresponding package directory. The file name matches the flow definition's unique full name, with a .flowDefinition extension. It became available in API version 34.0 and later.
Key fields in FlowDefinition include:
- activeVersionNumber: The version number of the active flow
- description: Description of the flow definition
- masterLabel: Label for the flow definition
Deployment Issues
Deploying FlowDefinition can present several challenges:
1. Version Compatibility
With the introduction of Salesforce API version 44 and onwards, it is recommended not to use FlowDefinition metadata to define which version of the Flow is active in the org. This change means that only the latest version of a Flow can be retrieved and deployed from Salesforce via Metadata API when using v44 or later.
2. Activation Status
Flows typically deploy in a deactivated state by default. Including a FlowDefinition in the deployment package can activate the proper version of the flow, but this can lead to unexpected behavior if not managed carefully.
3. Invalid Version Numbers
Deploying a FlowDefinition referencing a version of a Flow that won't be present in the target environment after deployment can result in an "Invalid version number" error.
Best Practices for Salesforce Administrators
1. Upgrade to Latest API Version
Administrators should consider upgrading their flows to use flow metadata file names without version numbers and discontinue using the FlowDefinition object to activate or deactivate flows. Instead, use the Flow object for activation and deactivation.
2. Careful Version Management
When deploying with flow definitions, be aware that the active version numbers in the flow definitions override the status fields in the flows. Ensure that the intended version is specified in the FlowDefinition.
3. Comprehensive Deployment Packages
Include all necessary components in your deployment package. If deploying a FlowDefinition, ensure that the corresponding Flow is also included in the package or already exists in the target environment.
4. Use Sandbox Testing
Always test flow deployments in a sandbox environment before moving to production. This practice helps identify and resolve any issues related to FlowDefinition and Flow versioning.
5. Implement Naming Conventions
Adopt clear and consistent naming conventions for flows and flow definitions. This practice enhances maintainability and makes it easier to manage multiple flows across different environments.
6. Document Flow Changes
Maintain detailed documentation of flow changes, including version updates and activation status. This documentation is crucial for troubleshooting deployment issues and maintaining a clear history of flow evolution.
7. Consider Alternative Approaches
For complex automation scenarios, consider using a combination of flows, Apex triggers, and other declarative tools. This approach can help mitigate some of the challenges associated with FlowDefinition deployments.
Conclusion
While FlowDefinition has been a useful tool for managing flow versions and activation in Salesforce, recent API changes have altered best practices. Salesforce administrators should stay informed about these changes and adapt their deployment strategies accordingly. By following the best practices outlined in this paper, administrators can more effectively manage flows across their Salesforce environments, minimizing deployment issues and ensuring smooth operations.