Loading

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

Publiseringsdato: May 26, 2026
Beskrivelse

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:

  1. Create two Date fields named Test1 and Test2
  2. Create a Formula field called duration with output type Number and formula syntax: Test1__c - Test2__c + 1
  3. Update a few records with values in Test1 and Test2, then save (this populates the formula field with a numeric value)
  4. Attempt to change Test1's data type from Date to Date/Time

The 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.
Løsning

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.

Temporary Workaround — Comment Out the Formula Reference

To temporarily disable the formula reference while making the data type change:

  1. Navigate to Setup > Object Manager > [Object] > Fields & Relationships
  2. Open the formula field (in the example, the duration field)
  3. Comment out the reference to the field being changed. For example:

 

/*Test1__c - Test2__c*/ + 1
  1. Save the formula field
  2. Return to the field whose data type you want to change and make the update
  3. After the data type change is complete, update the formula field to restore the correct syntax that reflects the new data type

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.

Knowledge-artikkelnummer

000385523

 
Laster
Salesforce Help | Article