+ Start a Discussion
abhishek kamthanabhishek kamthan 

null: Must specify a nameField of type Text or AutoNumber

Hi,

When i am trying to create Custom Object Using Metadata Api in C# i am getting following error:
null: Must specify a nameField of type Text or AutoNumber

CustomObject cObject = new CustomObject();
            cObject.fullName = "Vistaa__c";
            cObject.deploymentStatus = metaforce.DeploymentStatus.Deployed;
            cObject.deploymentStatusSpecified = true;
            cObject.description = "Created by metadata API";
          
            cObject.enableActivities = true;
            cObject.enableActivitiesSpecified = true;
            cObject.label = "Vista Object";
            cObject.pluralLabel = cObject.label + "s";
            cObject.sharingModel = metaforce.SharingModel.ReadWrite;
            cObject.sharingModelSpecified = true;
            CustomField cf = new CustomField();
            cf.description = "Simple text field from API";
            cf.fullName = "Lead." + cObject.fullName + "__c";
            String fieldLabel = "";
            cf.label = fieldLabel.Length == 0 ? "Sample Field" : "Sample Field";
            cf.length = 50;
            cf.type = FieldType.Text;
            cObject.nameField = cf;

            SaveResult[] results = ms.createMetadata(new metaforce.Metadata[] { cObject });
 
Gaurav NirwalGaurav Nirwal
CustomObject co = new CustomObject();
String name = "SFTestObject";
co.setFullName(name + "__c");
co.setDeploymentStatus(DeploymentStatus.Deployed);
co.setDescription("Created by the Metadata API");
co.setEnableActivities(true);
co.setLabel(name + " Object");
co.setPluralLabel(co.getLabel() + "s");
co.setSharingModel(SharingModel.ReadWrite);
CustomField nf = new CustomField();
nf.setType(FieldType.Text);
nf.setLabel(co.getFullName() + "TEST1");
CustomField nf1 = new CustomField();
nf1.setType(FieldType.Text);
nf1.setLabel(co.getFullName() + "TEST2");
CustomField nf2 = new CustomField();
nf2.setType(FieldType.Text);
nf2.setLabel(co.getFullName() + "TEST3");
CustomField[] fieldsArray = new CustomField[]{nf, nf1, nf2};
co.setFields(fieldsArray);
AsyncResult[] ars = metaBinding.create(new Metadata[] { co} );
abhishek kamthanabhishek kamthan
Hi,
I am using metadata api.
SaveResult[] results = ms.createMetadata(new metaforce.Metadata[] { cObject });
MetaData Api have new methods createMetadata

Can you please share full C# code to create custom object using metadata api.

Thanks in advance.