Skip to main content

Deleting a custom field referenced by old flow versions

When trying to delete a field you may receive a Salesforce validation error stating "This custom field is referenced elsewhere in salesforce.com" because of previous flow versions referencing this field

Nicole Bazarova avatar
Written by Nicole Bazarova
Updated this week

The Problem

If you are trying to delete a field, Salesforce will not allow you to deploy this deletion if the field is referenced in any flow in the target -- even in any deactivated older flow versions.

Let's imagine you have a Flow A that references Field B. You want to delete Field B, so you:

  1. Create a new version of Flow A that removes the reference to Field B.

  2. Delete the previous versions of Flow A that reference Field B.

  3. Delete Field B itself.

If you now select the changed Flow A and deleted Field B for deployment, you will face the following validation error:

The manual resolution to this error is to delete the flow versions from the target environment before attempting to deploy the field deletion. However, this requires updating environments directly, and lacks a robust audit trail.

The approach detailed below is likely to work with other metadata types used in Flows too (such as Apex), but reach out to us in the chat if you have any questions!

How to resolve this with Gearset Pipelines

Gearset's Pipelines will automatically validate your PR and return the same failed error message from Salesforce. If you have deployment access to the target environment, you can then use the "manually resolve" option to split this deployment into steps Salesforce will accept:

  1. Deploying the changed flow

    1. Select "manually resolve" on the PR -- this will run a comparison from the source branch to the target environment

    2. Make sure the changed version of the flow is set to active, then select just the flow and deploy it to the target environment.

  2. Deleting the previous flow versions

    1. Select "manually resolve" on the PR again, and this time change the comparison API version to API version 43 or below (which will allow you to retrieve all flow versions)

    2. In the comparison, select all previous versions of the flow -- these should all show as deletions. Make sure not to select the latest version as you will then delete the flow entirely from the target!

    3. Deploy the older versions of the flow to delete them from the environment

  3. Deploying the field deletion

    1. As the flow versions have now been deleted, you can re-run the validation of the PR and this should now succeed. You can then merge the PR as normal, which will delete the field from the target

How to resolve this with Gearset Compare & Deploy

If you are using Gearset's org to org comparison, you can also delete a field referenced by older flow versions by following these steps:

  1. Deploying the changed flow

    1. Run a comparison with the changed flow. Ensure the latest flow version is set to active. Deploy just this changed flow

  2. Deleting the previous flow versions

    1. Run another comparison, but this time change the comparison API version to API version 43 or below (which will allow you to retrieve all flow versions)

    2. Select all previous versions of the flow -- these should all show as deletions. Make sure not to select the latest version as you will then delete the flow entirely from the target!

  3. Deploying the field deletion

    1. As the flow versions have now been deleted, you can now run a final comparison to select the deleted field. Deploy the deleted field, and you're done!

Did this answer your question?