+ Start a Discussion
ALEX YAN 7ALEX YAN 7 

Metadata API for adding picklist values to a particular record type

Hello, I want to add new picklist values  through Metadata API for a particular recordtype. but the existing picklist values are removed when I assign new values .Can someone tell me how to do .Thank you very much

    public static void updatePicklistByRT()
    {    
        
         MetadataService.MetadataPort service = createService();
         MetadataService.RecordType rt = new MetadataService.RecordType();
          rt.active = true;
         // rt.fullName = 'Product2.Model';
         // rt.label = 'Model';
         // rt.businessProcess='Model';
            rt.fullName = 'Case.IHOST';
          rt.label = 'IHOST';
          rt.businessProcess='IHOST';
          // Add pick list values
        metadataservice.PicklistValue two = new metadataservice.PicklistValue();
        two.fullName= 'second1rd';
        two.default_x=false;
        metadataservice.PicklistValue three = new metadataservice.PicklistValue();
         three.fullName= 'third1rd';
        three.default_x=false;
 
    MetadataService.RecordTypePicklistValue ohmVersions = new MetadataService.RecordTypePicklistValue();
 //  ohmVersions.Picklist = 'Product_Segment__c';
    ohmVersions.Picklist = 'casetest__c';
   
     ohmVersions.values = new MetadataService.PicklistValue[] { two,three};
      rt.PicklistValues = new MetadataService.RecordTypePicklistValue[] { ohmVersions };

    List<MetadataService.SaveResult> results =
            service.updateMetadata(
                new MetadataService.Metadata[] { rt });
      handleSaveResults( results[0]);
    }