0

Using MetaData API, am able to insert the value in Picklist field in apex code but it is not available for any record type. I am finding hard to expose the value to record type. Here is my code,

public static void updatePicklistFieldTA(string ta, string sessionId)
{
    MetadataService.MetadataPort service = createService(sessionId);
    MetadataService.CustomField customField = new MetadataService.CustomField();
    customField.fullName = 'Case.Technology_Area__c';
    customField.label = 'Technical Area';
    customField.type_x = 'Picklist';
    metadataservice.Picklist pt = new metadataservice.Picklist();
    pt.sorted= false;
    metadataservice.PicklistValue three = new metadataservice.PicklistValue();
    three.fullName= ta;
    three.default_x=false ;
    pt.picklistValues =  new list<metadataservice.PicklistValue>{three};
    customField.picklist = pt ;
    List<MetadataService.SaveResult> results =
        service.updateMetadata(
            new MetadataService.Metadata[] { customField });
    handleSaveResults(results[0]);
    // Get the values for the picklist

}

I found many articles regarding this but there is no solution.

Any help would be appreciated!.

2
  • Please note that there are problems in the provided answer. – mohammed azarudeen May 4 '18 at 16:21
  • MetadataService.CustomField picklistField = (MetadataService.CustomField) service.readMetadata( 'CustomField', new String[] { 'Account.Industry' } ).getRecords()[0]; - This returns NULL values for everyone – mohammed azarudeen May 4 '18 at 16:21