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
abhishek kamthanabhishek kamthan 

null: Must specify a nameField of type Text or AutoNumber

Hi
I am getting following error when i am trying to create custom object
System.Web.Services.Protocols.SoapHeaderException: null: Must specify a nameField of type Text or AutoNumber

my code is as follows:

metaforce.CustomObject co = new metaforce.CustomObject();
                co.deploymentStatus = metaforce.DeploymentStatus.Deployed;
                co.deploymentStatusSpecified = true;
                co.description = "My Custom Object created from .NET";
                co.fullName = "DotNetCustomObject__c";
                co.label = "DotNet Custom Object";
                co.pluralLabel = "DotNet Custom Objects";
                co.sharingModel = metaforce.SharingModel.ReadWrite;
                co.sharingModelSpecified = true;
                co.enableActivities = true;


                CustomField nf = new CustomField();
                nf.type=FieldType.Text;
                nf.label= "DotNetCustomObject__c"+" Name";
                co.nameField = nf;
                SaveResult[] results = ms.createMetadata(new metaforce.Metadata[] { co });
Best Answer chosen by abhishek kamthan
Lee WonLee Won
Found the problem. Had to add the line:

co.nameField.typeSpecified = true;

All Answers

RamuRamu (Salesforce Developers) 
I came across one of the posts where someone mentioned that you would need to create the custom object before you create the custom field. Try inserting the create statement before inserting the custom field data. See if this helps.
nitesh gadkarinitesh gadkari
Hi abhishek kamthan,

there is a compulsory Name(system field) associated with each custom object which has to have some value.It can be of 2 types-
1)either auto number (In this case you just declare it as autonumber type meaning it will generate its value everytime a new record is created).No need to worry in this case when dealing through apex

2)Text type(80 characters): here you have to to compulsory enter a value when you create record thorough apex before inserting 

else it is going t give you error.


Regards 
Nitesh 
abhishek kamthanabhishek kamthan
Hi all,

 i am using salesforce and meta wsdl for loging and creating custom object.
when i saw metadataServerUrl which i am getting is:

"https://ap1.salesforce.com/services/Soap/m/31.0/00D90000000yzBq"

if i am hitting this url i am getting following error is that the issue that i am not able to create custom object.

HTTP ERROR 405

Problem accessing /services/Soap/m/31.0/00D90000000yzBq. Reason:

    GET not supported


Full code is as follows:
protected void Page_Load(object sender, EventArgs e)
        {
            MetadataCreator mc = new MetadataCreator("contact.kamthan@gmail.com", "rajendra@578JYVhVRgHp6n6rmvxpFYTUgvAH");
            mc.Create();
        }

        class MetadataCreator
        {
            private metaforce.MetadataService ms;
            private sforce.SforceService ss;

            public MetadataCreator(String username, String password)
            {
                ss = new sforce.SforceService();
                sforce.LoginResult lr = ss.login(username, password);

                ss.Url = lr.serverUrl;
                ss.SessionHeaderValue = new sforce.SessionHeader();
                ss.SessionHeaderValue.sessionId = lr.sessionId;



                ms = new metaforce.MetadataService();
                ms.Url = lr.metadataServerUrl;
                ms.SessionHeaderValue = new metaforce.SessionHeader();
                ms.SessionHeaderValue.sessionId = lr.sessionId;
               

            }


           
            public void Create()
            {
                metaforce.CustomObject co = new metaforce.CustomObject();
                co.deploymentStatus = metaforce.DeploymentStatus.Deployed;
                co.deploymentStatusSpecified = true;
                co.description = "My Custom Object created from .NET";
                co.fullName = "DotNetCustomObject1__c";
                co.label = "DotNet Custom Object";
                co.pluralLabel = "DotNet Custom Objects";
                co.sharingModel = metaforce.SharingModel.ReadWrite;
                co.sharingModelSpecified = true;
                co.enableActivities = true;
               
                co.nameField = new metaforce.CustomField();
                co.nameField.label = "ID";
                co.nameField.type = metaforce.FieldType.AutoNumber;
                co.nameField.description = "dsfdsfsdfsd";
                co.nameField.fullName = "DotNetCustomField1__c";
               
                //co.nameField.length = 100;
                //co.nameField.lengthSpecified = true;


                //ms.createMetadataAsync(new metaforce.Metadata[] { co });
                SaveResult[] results = ms.createMetadata(new metaforce.Metadata[] { co });
Lee WonLee Won
Did you ever solve this problem?  I have the same issue.  I keep getting a 'Must specify a nameField of type Text or AutoNumber'  error even though my code IS specifying a nameField with type Text.

My code looks like  this:
 
CustomObject co = new CustomObject();
co.deploymentStatus = DeploymentStatus.Deployed;
co.deploymentStatusSpecified = true;
co.enableActivities = true;
co.sharingModel = SharingModel.ReadWrite;
co.sharingModelSpecified = true;
co.description = "Service Center device.";
co.fullName = DEVICE_OBJECT_NAME;
co.label = DEVICE_OBJECT_LABEL;
co.pluralLabel = DEVICE_OBJECT_LABEL_PLURAL;
co.nameField = new MetadataApi.CustomField();
co.nameField.type = MetadataApi.FieldType.Text;
co.nameField.length = 80;
co.nameField.lengthSpecified = true;
co.nameField.label = "Name";
co.nameField.fullName = "LPDevice__c.Name__c";

SFConnector.MetadataApi.SaveResult[] res = this.metadataService.createMetadata(new Metadata[] { co });
          

 
Lee WonLee Won
Found the problem. Had to add the line:

co.nameField.typeSpecified = true;
This was selected as the best answer
abhishek kamthanabhishek kamthan
Hi Lee Won,
It works.

Thanks a lot.......
Abhishek Kamthan