Skip to content

Can not change field type to a formula field

Detection

  • RegExp: Error (.*) Cannot update a field from a Formula to something else

Examples

  • Error Account.Score__c Cannot update a field from a Formula to something else

Resolution

Salesforce can not turn formula field {1} into another type with a deployment.
- Before the deployment, rename {1} into {1}_ToDel in the target org (or delete it), so the deployment creates {1} with its new type
- Once the deployment is done, delete {1}_ToDel
- The manual deployment action below reminds to do it in each org of the pipeline, with a checkbox in the Pull Request comments

Deployment action

A deployment action can solve this error. Create it on the Pull Request of the current branch:

sf hardis:project:action:create --agent --scope pr --pr-id current --when pre-deploy --type manual --label "Rename formula field {1} before its type changes" --instructions "1. In Setup, open Object Manager, the object of {1}, then Fields & Relationships
2. Open {1}, click Edit, add _ToDel at the end of its Field Name, and Save
3. After the deployment, delete the _ToDel field
4. If {1} already has its new type, there is nothing to do"

Documentation: https://sfdx-hardis.cloudity.com/salesforce-devops-work-on-user-story-deployment-actions-manual/

Comments