+ Start a Discussion
mani toolmani tool 

Error : MetadataService.UpdateMetadata

I have a custom field, I have to edit the field using metadata api.
 I used below code :

MetadataService.MetadataPort service = new MetadataService.MetadataPort();  
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();
//system.debug('session id:'+UserInfo.getSessionId());
        MetadataService.CustomField customField = new MetadataService.CustomField();
        customField.fullName = 'custom_create__c.TestField__c';
        customField.label='New Test Field Label';
        customField.type_x = 'Text'; 
        customField.length = 52;
        MetadataService.UpdateMetadata ut = new MetadataService.UpdateMetadata();
        ut.metadata= customField;
        MetadataService.AsyncResult[] results = service.updateMetadata(new List<MetadataService.updateMetadata> {ut});

Iam getting an error: "Invalid type: MetadataService.UpdateMetadata".
Can anyone plz suggest why im getting this error.
Hi Mani,
Mark as best answer, If it resloves !!
you need to import all the classes from the metadata sample to get this workfing..
also your MetadataServiceExamples class should have all the methods to run.. your createObject method is calling createService method which is missing..

check this for all the classes in metadata sample and add them to your org

and this is for the MetadataServiceExample class

Mark as resloved if it helps :) :)
Bhanu Prakash
visit ForceLearn.com​ (https://www.forcelearn.com
mani toolmani tool
Hi Bhanu,

I have created an Object using metadata, Creating object/field is no issue. But the issue is at the time of updating the fields.