function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
krish4ukrish4u 

Metadata API for adding picklist values to a particular record type

I am adding picklist values in Selected Values through Metadata API for a particular recordtype. but the existing selected values are removing when i assign new values to Selected values.

how to get the existing values from RecordTypePicklistValue[] in Metadata API or else only those two new values to be added in the Selected Values.

Code:     

MetadataService.RecordType rt = new MetadataService.RecordType();
rt.active = true;
rt.fullName = 'Lead.Marketing';
rt.label = 'Marketing';

    // Add pick list values
        metadataservice.PicklistValue two = new metadataservice.PicklistValue();
        two.fullName= 'second';
        two.default_x=false;
        metadataservice.PicklistValue three = new metadataservice.PicklistValue();
        three.fullName= 'third';
        three.default_x=false;

MetadataService.RecordTypePicklistValue ohmVersions = new MetadataService.RecordTypePicklistValue();
ohmVersions.Picklist = 'Picklist__C';
ohmVersions.values = new MetadataService.PicklistValue[] { two,three};
rt.PicklistValues = new MetadataService.RecordTypePicklistValue[] { ohmVersions };

return handleSaveResults( service.updateMetadata( new MetadataService.Metadata[] { rt })[0]);
      

Thanks,
Krish
Daniel BallingerDaniel Ballinger
The Metadata Picklist.picklistValues (https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_picklist.htm) represents the complete state of the values for the object in question. You will need to pass through any existing values you want to keep in addition to any new values.
Mark Liu 13Mark Liu 13
Hey Daniel, would you please give an example as to how to query and automatically pass the existing picklistvalues into the class so that they can be updated?
Manuel Roldan-Vega 7Manuel Roldan-Vega 7
Is there a way to setup a RecordType so that all values added to the picklist are added to that RecordType list of available values also?