Can not change type due to existing data
Detection
- RegExp:
Error (.*) Cannot change type due to existing data
Examples
Error Account.Status__c Cannot change type due to existing data
Resolution
Records of the target org hold values that the new type of {1} can not keep. Changing the type of a field is usually not recommended. If it is really needed:
- Change the type of {1} manually in the target org before the deployment, if Setup allows it
- If Setup refuses it, update or remove what uses {1} (formulas, Flows...), and deploy them again later
- The manual deployment action below reminds to do it in each org of the pipeline, with a checkbox in the Pull Request comments
- More help: https://help.salesforce.com/s/articleView?id=000327186&type=1
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 "Change the type of field {1}" --instructions "1. In Setup, open Object Manager, the object of {1}, then Fields & Relationships
2. Open {1}, click Change Field Type, and select the type it has in the sources
3. If {1} already has this type, there is nothing to do"
Documentation: https://sfdx-hardis.cloudity.com/salesforce-devops-work-on-user-story-deployment-actions-manual/