The error "Cannot change type due to existing data" appears when you attempt to change the data type of a custom field that is already referenced by a Formula field in Salesforce. This error occurs in Setup, as well as when deploying changes via Change Sets or the Metadata API.
Salesforce prevents this type change because modifying the data type of a field that is referenced in a formula could invalidate the formula's syntax or produce incorrect results.
Example Scenario:
Test1__c - Test2__c + 1The following error appears:
Error: Can't change the data type because it's referenced in the following flows, formulas or filters. Formula Fields: duration
When the same change is deployed via Change Set or Metadata API, a similar error appears:
Cannot change type due to existing data.
Before changing the data type of a custom field, you must modify or remove any formula field references to that field to avoid a syntax conflict.
To temporarily disable the formula reference while making the data type change:
/*Test1__c - Test2__c*/ + 1
Important Note: If you choose to comment out the field reference, remember to update the formula again after the data type change is complete. Failing to restore the formula will result in the formula not collecting the correct data.
000385523

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.