3

By my reading of the docs, it should be possible to create a new SObject by POSTing to /tooling/SObjects/EntityDefinition, but I haven't made it work. Here's an example (the result of some trial-and-error, not all of which I have a record of), which I POSTed to /services/data/v34.0/tooling/sobjects/EntityDefinition:

{
    "Fullname" : "New_Object__c",
    "Metadata" : { 
        "label" : "New Object",
        "pluralLabel" : "New Objects"
    }
}

This returns the error:

[ {
  "message" : "Must specify a nameField of type Text or AutoNumber",
  "errorCode" : "FIELD_INTEGRITY_EXCEPTION",
  "fields" : [ ]
} ]

So then I tried:

{
    "Fullname" : "New_Object__c",
    "Metadata" : { 
        "label" : "New Object",
        "pluralLabel" : "New Objects"
    },
    "nameField" : {
             "DeveloperName" : "name", 
             "DataType" : "AutoNumber" 
     }
}

which returns the error:

[ {
  "message" : "No such column 'nameField' on sobject of type EntityDefinition",
  "errorCode" : "INVALID_FIELD"
} ]

Is it possible to create an SObject in this manner? I'd rather use Tooling API than Metadata API, as I'd like to stick to using REST.

Update: per the suggestion, I've moved nameField into the metadata hash like so:

{
    "Fullname": "New_sObject__c",
    "Metadata": {
        "label": "New Object",
        "pluralLabel": "New_Objects",
        "sharingModel": "ReadWrite",
        "deploymentStatus": "Deployed",
        "nameField": {
            "label": "qwerty",
            "type": "Text",
            "fullName": "asdfgh"
        }
    }
} 

Which results in:

[ {
  "message" : "insufficient access rights on cross-reference id",
  "errorCode" : "INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY",
  "fields" : [ ]
} ]

Confusing, as I'm not referencing any ids. I also tried "fullName" : "name" thinking that might be required.

  • What place in the documentation makes you think that you can create a new SObject by sending POST to /tooling/SObjects/EntityDefinition? As far as I can see the only place where /sobjects/SObjectName/ mentions POST is where POST used to create ApexExecutionOverlayAction. – gaiser Sep 19 '15 at 20:09
  • Well, good point; it's not explicitly listed as a use case. However, ApexExecutionOverlayAction seemed to be an example; I had hoped I could post to any sObject; also, comments I heard this week during a DF15 session (API Evolution session on Wed at 3pm, I think) led me to believe that the new Object Manager in Lightning Experience(!) was using the Tooling API , and EntityDefinition was called out specifically. – Jason Clark Sep 20 '15 at 1:05
  • 2
    EntityDefinition's own describe reports that it is createable: false. – Christian Carter Sep 20 '15 at 6:47
4

Current version (v34) of /tooling/sobjects works with Tooling API SObjects (e.g.MetadataContainer). You can use to it to create records of existing Tooling API Sobject types, not new custom object types (e.g. New_sObject__c) as in your example.

This is similar to how you can use normal (/xx.x/sobjects/SObjectName/) REST API endpoint to create new records of existing (non tooling API) objects.

Presently you can not use Tooling to create new arbitrary custom object (type). To create new SObject type(s) use Metadata API.

| improve this answer | |
0
I believe the namefield should be inside Metadata.



     {
    "Fullname": "New_sObject__c",
    "Metadata": {
        "label": "New Object",
        "pluralLabel": "New_Objects",
        "sharingModel": "ReadWrite",
        "deploymentStatus": "Deployed",
        "nameField": {
            "label": "qwerty",
            "type": "Text",
            "fullName": "asdfgh"
        }
    }
} 

Edit

Christian and gaisor are right. At this moment it is not possible to create objects via rest API as the Metadata rest API was put on hold.

The error you are getting is because you are trying to do something that is not supposed to be done like creating an entity which has creatable as false.

| improve this answer | |
  • Thanks Manjit; while it seems happy to have nameField moved into the metadata hash (and I'd love to know where that is documented), I'm still not able to create the object; see the additional information I've added to the original question for details. – Jason Clark Sep 20 '15 at 0:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.