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
Shabbir ShaikShabbir Shaik 

Creating objects through Metadata API

I am creating custom object from APEX but when i use this, getting problem

Initial expression is of incorrect type, expected: MetadataService.Metadata at line 39 column 50

can any body know this, Here is my code.


List<MetadataService.CustomObject> customObjectlst = new List<MetadataService.CustomObject>();
MetadataService.CustomObject customObject = new MetadataService.CustomObject();
//customObject.nameField = 'Test__c';
customObject.label = 'Test';
customObject.pluralLabel = 'Tests';
customObject.nameField = new MetadataService.CustomField();
customObject.nameField.type_x = 'Text';
customObject.nameField.label = 'Test Record';
customObject.deploymentStatus = 'Deployed';
customObject.sharingModel = 'ReadWrite';
customObjectlst.add(customObject);

List<MetadataService.SaveResult> results = meta.createMetadata(
                new MetadataService.Metadata[] { customObjectlst });      
        handleSaveResults(results[0]);

Best Answer chosen by Shabbir Shaik
Shabbir ShaikShabbir Shaik
Solved it!

i modified Metadataservice class its working for me...

Good job every one!

All Answers

Shabbir ShaikShabbir Shaik
Here I am getting problem when am going to assign custom object list/(custom object) to MetadataService.Metadata[],

How can i overcome this problem can anybody know this?
AshwaniAshwani
Salesforce doesn't parse Metadata class in proper way. You have to extend the "MetadataService.CustomObject" with Metadata class. 
Bhawani SharmaBhawani Sharma
This is definitely possible. See the below link.
https://github.com/BhawaniSharma/apex-mdapi
Shabbir ShaikShabbir Shaik
Hi,

can you please give clarity or example to extend the "MetadataService.CustomObject"

Actually my problem is assigning customobject to metadataservice.metadata,

MetadataService.MetadataWebSvc  meta=new MetadataService.MetadataWebSvc();

MetadataService.AsyncResult[] results = meta.create(new List<MetadataService.Metadata> { customObject });
Shabbir ShaikShabbir Shaik
Solved it!

i modified Metadataservice class its working for me...

Good job every one!
This was selected as the best answer
Balraj SinghBalraj Singh
Hi Shabbir,

Can you please explain what exactly you have modified in MetadataService class b/c i am facing the same problem but didn't get any solution.