I am using metadata API to add picklist value('custom') in a field.I have a record type (AAM_T) created which has to be associated with value I have added to picklist, but as on running : service.updateMetadata( new MetadataService.Metadata[] { recordType }); causing an error 'System.CalloutException: IO Exception: Read timed out'.

MetadataService.PickListValue objPickListValue = new MetadataService.PickListValue();
objPickListValue.fullName = 'custom';
objPickListValue.default_x = false;

MetadataService.RecordType recordType = (MetadataService.RecordType) 
                                        service.readMetadata('RecordType',
                                        new String[] { 'Account.AAM_T'}).getRecords()[0];

MetadataService.RecordTypePicklistValue[] recordPickListType =  recordType.picklistValues;

if(recordPickListType.size() > 0){
   for(MetadataService.RecordTypePicklistValue rpk : recordPickListType) {
       if(rpk.picklist == picklistToUpdate){
            rpk.values.add(objPickListValue);
            break;
       }
    }

    try{
         service.updateMetadata( new MetadataService.Metadata[] { recordType });
       } catch(Exception ex){
          system.debug('@@@getStackTraceString : '+ex.getStackTraceString());
          //Result: System.CalloutException: IO Exception: Read timed out -- null
          system.debug('@@@getMessage : '+ex.getTypeName() 
                       + ': ' + ex.getMessage() + ' -- ' + ex.getCause());

        }

  }
1

There are 1 best solutions below

0
Ram Manohar On

You can try this like any other webservice. worked to me

MetadataService.MetadataPort service = new MetadataService.MetadataPort();

service.timeout_x=120000;