+ 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());
System.debug(UserInfo.getOrganizationId()+''+UserInfo.getSessionId().SubString(15));    
        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.currentName='custom_create__c.TestField__c';
        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.
bhanu_prakashbhanu_prakash
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
https://github.com/financialforcedev/apex-mdapi/tree/master/apex-mdapi/src/classes

and this is for the MetadataServiceExample class
https://github.com/financialforcedev/apex-mdapi/blob/master/apex-mdapi/src/classes/MetadataServiceExamples.cls

Mark as resloved if it helps :) :)
Thanks, 
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.