[SalesForce] Metadata Api: Unable to update to active values for picklist in record type

I am trying to update the record type to move the picklist values to the 'active values' . I am using the metadata api. Below is my code where Scope_Of_Services_Tasks__c is the name of object , Meeting_Type__c is the field name and Project_Management is the name of the Record type :-

MetadataService.RecordType rt = new MetadataService.RecordType();
rt.active = true;
rt.fullName = 'Project_Management';
rt.label = 'Project Management';
MetadataService.PicklistValue pv = new MetadataService.PicklistValue();
pv.fullName = 'test123';

MetadataService.RecordTypePicklistValue ohmVersions = new MetadataService.RecordTypePicklistValue();
ohmVersions.Picklist = 'Meeting_Type__c';
ohmVersions.values = new MetadataService.PicklistValue[] { pv };
rt.PicklistValues = new MetadataService.RecordTypePicklistValue[] { ohmVersions };


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

The code is giving this error :- "Web service callout failed: WebService returned a SOAP Fault: '' is not valid for type xsd:boolean, should be '0', '1', 'true' or 'false' faultcode=soapenv:Client faultactor="

PLease help me out as this is very urgent and I am trying since more than 2 days. Thanks

Update:- pv.fullName = 'test123'; here 'test123' is the picklist value that need to be moved to the active values in the record type picklist.

Best Answer

Here is your issue

I'm presuming you are using the Apex wrapper to the metadata API as found here

  1. In order to use the service.updateMetadata(..) method, you first need to use the readMetaData(..) method for the metadata object you intend to update. In your case, this is the MetadataService.RecordType
  2. The Apex Metadata API wrapper will take the JSON response from the Metadata API and deserialize into the various MetadataService wrapper classes that represent the MetaDataService.RecordType and its child object collections
  3. All of the wrapper class fields will be properly populated to mirror what is in SFDC. Hence, all of the Boolean fields will have values.
  4. You then need to modify the datastructure, taking care not to smash lists of existing values to add the new picklist item to an existing recordType's picklist of interest.
  5. Finally, you can do the updateMetaData(..)

A close relevant example provided in class MetadataServiceExamples is method updatePicklist() where you can see the readMetaData(..) call preceding the updateMetadata() call.

Related Topic