0

I habe a code that should add new picklist value in all RecordTypes but after run it i get an error in method updateMetadata "System.CalloutException: 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". I use MetadataService from this repo. Any suggestion to get it worked?

MetadataService.MetadataPort service = new MetadataService.MetadataPort(); 
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();

MetadataService.CustomField picklistField = (MetadataService.CustomField) service
    .readMetadata('CustomField', new String[] { 'Employee__c.Job_Title__c' }).getRecords()[0];

MetadataService.CustomValue[] pickVals = picklistField.valueSet.valueSetDefinition.value;

/*
MetadataService.CustomValue newPickVal = new MetadataService.CustomValue();
newPickVal.fullName = 'New Picklist Value';
newPickVal.default_x = false;
newPickVal.isActive = null;
pickVals.add(newPickVal);
*/

String[] recordTypeNames = new String[] {'Hiring'};
MetadataService.Metadata[] mdRecordTypes = service.readMetadata('RecordType', recordTypeNames).getRecords();
MetadataService.RecordType[] recordTypes = (MetadataService.RecordType[]) mdRecordTypes;

MetadataService.RecordTypePicklistValue[] rtPickValues = new MetadataService.RecordTypePicklistValue[]{};
MetadataService.RecordTypePicklistValue rtPickValue = new MetadataService.RecordTypePicklistValue();
rtPickValue.picklist = 'Job_Title__c';
rtPickValue.values = pickVals;
rtPickValues.add(rtPickValue);
    
for(MetadataService.RecordType RT : recordTypes){
    RT.PicklistValues = rtPickValues;
    //System.debug(Json.serialize(RT.PicklistValues));
}

service.updateMetadata(new MetadataService.Metadata[] { mdRecordTypes[0] });

1 Answer 1

2

You need to include isActive, which must be 'true' or 'false'. It can't be an empty string.

4
  • For which class? @sfdcfox Mar 23, 2021 at 13:02
  • @DenisTitarenko newPickVal.isActive = null; should be true or false. Also, currently commented out, but that's what you're missing.
    – sfdcfox
    Mar 23, 2021 at 13:19
  • @ sfdcfox Thanks, I tried to uncomment this piece of code and assigning the value true and the error is still there. The error appears when this piece of code is commented out, so probably the error is in another place Mar 23, 2021 at 13:26
  • @DenisTitarenko Ah, well, you'll need to check the docs then. You've got a missing, required Boolean value.
    – sfdcfox
    Mar 23, 2021 at 14:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .