function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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());
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.
 
SandhyaSandhya (Salesforce Developers) 
Hi,

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
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

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,
Sandhya
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.