+ Start a Discussion
mani toolmani tool 

Invalid type: 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.
SandhyaSandhya (Salesforce Developers) 

You need to import all the classes from the metadata sample to get this working. 
Check this for all the classes in metadata sample and add them to your org

and this is for the MetadataServiceExample class

Also, do you have the latest version of the MetadataService.cls class from this repo in your org? You must use the one from this repository and not the default generated one from Salesforce.

Best Regards,
mani toolmani tool
Hi Sandhya, 

I have imported all the classes and its working fine at the time of creating an object and their fields but at the time of update it is throwing an error.