8

Sometimes we need to change the label or, more commonly, a value for a picklist item.

Suppose we do change the fullName attribute of a picklist field, to match an external system that will integrate with the platform, for example. And we have the code in our repository and a sandbox where the code is deployed to.

On the first iteration, the fullName is A, but on the next iteration of the code, the external system's administrator realizes that s/he passed the wrong value, and it is actually B. So of course, we change that on the fullName of the value in your Field__c.field-meta.xml file.

However, if we deploy this modified metadata, we will get the "duplicate label" error when using sfdx force:source:deploy:

Error src/objects/Object__c.object Object__c.Field__c Duplicate label: A's Label

Is there a way to force a deployment to change the current value, or maybe automate the deletion/replacement of the previous one?

  • I'm not aware of an automated way, but if you ensure that you don't change the existing picklist value in your metadata, but rather deactivate (change label as requried) and add a new one, you can deploy that via CLI. You would then have to manually do a Replace on the picklist values in all your environments though. – packo_cz Mar 9 at 21:03
0

You need to delete the field with Developer Name A and create a field with Developer Name B.

If you working with Salesforce Scratch Orgs, you just need either manually delete field Object__c.A__c from the source code base or make this change on scratch org and then pull this change to source code base. Finally you just do push to push the change to the desired scratch org.

  1. sfdx force:source:push

If you are working with Salesforce Sandboxes or Development org, then you need to

  1. sfdx force:source:delete -m Object__c.A__c
  2. sfdx force:source:deploy -m Object__c.B__c
| improve this answer | |
  • I know it is possible to rename the file and delete/deploy the field on the org. But this isn't - as far as I know - a trivial task to automate in a CI pipeline. The key here is "automate". :) – Renato Oliveira Mar 30 at 13:13
  • 2
    I agree this is not trivial but this is possible to automate. Also, if you are using Metadata API, you could potentially benefit from renameMetadata method, which does rename in one step instead of two steps – p-p Mar 30 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.