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?
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.
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
- 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.
- 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'.