Activity Forums Salesforce® Discussions How can I create custom object using the Metadata API from Apex? Reply To: How can I create custom object using the Metadata API from Apex?

  • Gourav

    Member
    April 29, 2016 at 7:59 am

    Use this code in your Apex class to create custom Object :-

     

    MetadataService.CustomObject customObject = new MetadataService.CustomObject();
    customObject.fullName = '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';
    MetadataService.AsyncResult[] results = service.create(new List<MetadataService.Metadata> { customObject });