[SalesForce] Writing nested custom object records

I am using the REST API to write a set of nested records to a Salesforce developer org. I can successfully run the sample on this help page and can also write a custom object record with no nested children. What I cannot do is write a record with children nested in it. The error I get reports an INVALID_FIELD with message "No such column 'Areas__r' on sobject of type Job__c". Here's a cut down version of the JSON I am sending through:

{"records": [
    {
        "Areas__r": {
            "records": [
                {
                    "attributes": {
                        "referenceId": "ref1a",
                        "type": "Area__c"
                    },
                    "name": "some area"
                }
            ]
        },
        "Job_details__c": "Some job details",
        "attributes": {
            "referenceId": "ref1",
            "type": "Job__c"
        },
        "custom_field__c": "some custom field value"
    }
]}

Note that I have also tried replacing "Areas__r" with "Areas", "Areas__c", "Area__c". Still get the same problem. Area__c has a master detail relationship to Job__c.

Best Answer

Refer to Understanding Relationship Names

JSON that you have provided is valid.

Goto custom object definition Area and make sure that

Plural Label    Areas

This name + '__r' will be used as relationship name for parent object

just in case make sure that you are using right service:

salesforce.com/services/data/v35.0/composite/tree/Job__c/
Related Topic