1

Suppose there are three picklist values "a", "b", and "c". With the mentioned values there are records in that object. I want to replace "a" with "x" , "b" with "y" and "c" with "z". Can we do this using meta data API?

0

4 Answers 4

2

You cannot replace existing values with new ones with the metadata API. If you migrate the picklist field with values X, Y and, Z then the existing picklist values A, B and, C get deactivated in the configuration. There will be no change to the data records using those values - you will simply be unable to select A or B or C henceforth in the Page Layouts.

Depending on the number of picklist values you are replacing, the options as I see it are: 1) doing it manually using Salesforce UI's replace function 2) running SOQL update statements to update field = X where field = A 3) creating a new field with appropriate values and deprecating this field

There might be more obviously but I don't see an easy way out. Please educate if there is a fourth option that is elegant.

Good luck.

Sridhar

1

Based on my tests using V31 and the Apex wrapper for the Metadata API at https://github.com/financialforcedev/apex-mdapi , the following seems to be true if manipulating CustomField member variable pickList, of type PickList with corresponding member variable pickListValues of type PickListValue[] .

  1. You can use the metadata API to change the value of pickList field A, entry 'Foo' to 'Bar'. You can also add new entries and remove entries. You can change/add/remove multiple picklist entries in one call.
  2. Any change of entry 'Foo' to 'Bar' will not change existing records holding values of 'Foo'. New records will be given the option of 'Bar' in lieu of 'Foo'.
0

You can change the label with the Metdata API or a force:source:deploy but changing the value creates a new picklist entry. Trying to change the value in VS Code then force:source:deploy results in a "duplicate label" error.

From @cropredy's response above, seems like the same is true.

I agree, seems like the only option is to do a SOQL update

-1

Do you have a lot of the picklist values to be changed? If there are not much, you can just do it from salesforce. You can even update the data if I am correct.

Just go to the picklist and replace the values. This will change the values and update the data.

1
  • 1
    This does not in anyway answers the OP's query. This should be a comment.
    – Sam
    Commented Aug 21, 2014 at 4:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .