How to deploy Flows in Salesforce

How to deploy Flows in Salesforce

David Runciman on

Share with


Most businesses want automated processes and workflows in their Salesforce orgs, and Flows are the go-to way for Salesforce teams to deliver on these requirements.

Executing business logic is rarely simple and so Flows can be pretty complicated to build. But deploying a Flow from sandbox to production, perhaps via source control, without the right tools can be even harder. If you’ve had countless change sets fail because of Flows or just want to get to grips with deploying Flows, this guide is for you.

What are Flows in Salesforce?

Flows are a powerful tool on Salesforce for adding automated business processes. They give admins and low-code developers an exciting opportunity to create business logic — what once required Apex code can now be built declaratively with a Flow. There are different types of Flow: Screen Flows involve direct interactions by end users on a Lightning page, while Schedule-Triggered Flows, Autolaunched Flows, Record-Triggered Flows, and Platform Event-Triggered Flows all run behind the scenes.

Flows are currently just part of the toolset on Lightning Flow, the process automation feature on Salesforce that contains Flow Builder, Process Builder and Workflow Rules. You can build simple automation in Process Builder, but Salesforce has been investing heavily in Flows for years. In fact, Process Builder and Workflow Rules are set to be retired this year — existing Processes will continue to be supported but you won’t be able to create new automation. So plenty of teams will begin to migrate from Process Builder to Flows.

Live eventConvene, Chicago

DevOps Dreamin' Chicago 2024

Find out more

What Flow metadata types are there?

There are a handful of Flow-specific metadata types you may end up working with for Salesforce Flow deployments.

  • Flow. This metadata represents the Flow itself.
  • FlowCategory. Flows can be grouped together, and FlowCategory is the metadata type that represents those groupings.
  • FlowDefinition. In theory, Flow Definitions define the active version of a Flow. But Salesforce made significant changes to Flows in its Winter ‘19 release, and since then has recommended not using Flow Definitions.
  • FlowTest. If you’ve created any tests for your Flows, those are defined with FlowTest metadata.
  • FlowSettings. This metadata captures a whole range of possible settings, e.g. whether users can pause Flows.
  • FlowAccessess. This is a field on your Profiles or Permission Sets metadata that controls which Flows users have access to.

How to manage Flow versions

Managing versions is probably the most awkward feature of Flow deployments. Each time you make changes and save them, you create a new version of your Flow in that org. Salesforce imposes a limit of 50 versions for each Flow — if you hit that limit you’ll need to delete older versions.

These versions make deployments tricky. Historically, the Flow versions in your org were reflected in the API name of the Flow, e.g. MyFlow-1. Salesforce removed those version numbers in 2019, so that Flows would be easier to handle in source control. You’ll find our full explanation of the changes to the Metadata API in the Winter ‘19 release here, but there were two key implications:

  1. Flow versions easily get out of sync between orgs. When you deploy a Flow, it’s added to the target as a new version. The version number depends on the target org. If you iterate on a Flow in a dev org and end up deploying v5 to a target that currently has v2, it will be added as v3.

  2. It’s hard to deploy anything other than the latest Flow version. Since v44, the Metadata API only fetches the latest version of your Flow — whether it’s active or still in draft. If you need to deploy your latest active version but have begun drafting a new version, you need a workaround. This is where the semi-retired Flow Definitions can come in handy.

Gearset address these challenges to help you manage Flow versions:

  1. When you compare and deploy your metadata with Gearset, you can see everything that’s new, changed, or deleted. And you can see the exact changes you’re deploying, including the status of your Flows. Regardless of the Flow versions in your orgs, you’ll have full insight into the impact of your deployment before you deploy.

  2. Gearset lets you deploy using any version of the Metadata API, including v43 if you want to retrieve all Flow versions and choose which one to deploy. So if you want to try a workaround with v43, you can do that using Gearset. Just be aware the behavior of the deployment is not in line with the up-to-date experience. A changed version will be deployed as the same version number in the target, not added as a new version. And Flow Definitions are needed to set the status of your Flows.

Catching Flow dependencies

Missing dependencies are a classic cause of deployment failure, and Flows are a common culprit because they usually connect to lots of other metadata. There are the custom objects and fields your Flow interacts with, any list views and workflow alerts your Flow uses, and even other Flows if you have Flows triggering other Flows!

Gearset’s advanced dependency tracking and problem analysis helps you get your deployment packages right the first time. You can see all the dependencies between your metadata during any deployment. Even if you miss any items, one of Gearset’s problem analyzers will catch the missing dependencies and offer to add them to your deployment package.

How to deploy Flows using Gearset

Let’s look at how to deploy flows with Gearset. There are only a few steps you need to take for a successful deployment — you can sign up for a free trial of Gearset and follow along.

Step 1: Configure your comparison to include the right metadata

Select the source and target environments for your deployment — whether you’re deploying to an org or committing to source control, the workflow is the same. Make sure your comparison filter includes all the metadata types you’ll need to deploy. As well as types like Flow and FlowCategory, you’ll want types including Custom Object for any dependencies. Include any managed packages that your Flow depends on, too. When you’re ready, hit Compare now.

Gearset screenshot: metadata comparison filter with Flow types selected

Step 2: Select the metadata to deploy from your comparison results

Once Gearset has compared the metadata in your source and target, you’ll be able to see which items are new, changed, or deleted, and exactly what’s different for each item. Not only that, by clicking on the dropdown for any item, you’ll see all of its dependencies.

If your source and target are significantly out of sync, you may need to deploy any custom objects and fields your Flow depends on first — avoiding a bunch of validation errors.

Select the metadata items you want to deploy and click Next.

Gearset screenshot: Select items to deploy, see the exact differences between source and target, and dig into dependencies

Step 3: Deploy to your target environment

Gearset’s problem analysis will flag any issues with your deployment, including a host of Flow-specific errors. Once you’ve accepted any suggestions to make the deployment more likely to succeed, click Pre-deployment summary to check over the package, give it a friendly name, and leave any notes for your teammates.

Clicking Validate deployment is always a good idea, then hit Deploy now or click on the drop-up to schedule the deployment for a release window. You can download a report of the deployment from your Deployment history, where you can also redeploy to another org or roll back.

If you run into any unexpected issues, just reach out via the live chat! Our deployment experts are super speedy and available to help you get those changes live.

Help! How do I delete a Flow?

Trying to delete a Flow is yet another source of potential frustration, and there are two problems to overcome. Firstly, you can’t delete an active Flow. The second problem is more of a conundrum: in order to delete a Flow, Salesforce needs you to specify every version of the Flow, but from v44 of the Metadata API onwards you can’t retrieve and deploy specific versions.

Depending on the API version you use, you’re likely to hit one or both of these errors:

  • Insufficient access rights on cross-reference id
  • You cannot delete this Flow version because it is active. Deactivate it, and try again.

Thankfully, Gearset’s problem analysis resolves all of this for you. It disables the Flow, retrieves and deploys all the versions of the Flow, and deploys the destructive change successfully.

Get your deployments flowing!

Keep delivering the Flows that power your business’s automation, without getting blocked on deployments. Using Gearset is guaranteed to see more of your deployments work first time. And it’s not just Flows: Gearset helps you with all those vital but occasionally awkward metadata types that you need to get from your sandbox to production — including Profiles and Permission Sets, Layouts, Apex classes, and more. It’s quick and easy to get started on a free 30-day trial, so you can see for yourself.

Try all of Gearset for free