Loading

Error 'Cannot change type due to existing data' when you update custom field data types

Publiceringsdatum: Oct 13, 2022
Beskrivning
The error "Cannot change type due to existing data" can occur when attempting to update a custom field data type and the field is referenced by a Formula field.

For example:

1. Create 2 Date fields, Test1 and Test2 
2. Create a Formula field called "duration" with output 'Number' and syntax : Test1__c - Test2__c +1 
3. Update a few records with Test1 and Test2, Save. [This would populate the Formula field in question with a numeric value]. 
4. Go to one of the fields created in step 1 and change the field type to Date/Time. The follow error will occur: 

Error: Can't change the data type because it's referenced in the following flows, formulas or filters. 
Formula Fields: duration 

When attempting the same type of update using Change Sets or MetaData API, a similar error may occur:  "Cannot change type due to existing data."
Lösning
Before the field type can be changed, make sure to modify the syntax of the error message to ensure it does not conflict with the data type change.

As a temporary solution, comment out the field references in the formula field. For example: 

/*Test1__c - Test2__c*/ +1

Note: If choosing to comment out the field reference, remember to modify the formula again after the data type change is complete to accurately collect the desired data. 

Related Link:
Notes on Changing Custom Field Types
​​​​​​​
Knowledge-artikelnummer

000385523

 
Laddar
Salesforce Help | Article