0

ooks like I need some help here. Salesforce documentation and multiple google searches not gave me an answer.

Problem description: I'm trying to insert (POST) nested self-related records using REST with JSON, but every time this error appears:

{
"message": "Cannot deserialize instance of <unknown> from FIELD_NAME value records or request may be missing a required field",
"errorCode": "JSON_PARSER_ERROR"
}

JSON:

{
"records" :[{
     "attributes" : {"type" : "Test_Obj1__c", "referenceId" : "ref1"},
     "name" : "integr parent",
     "Test_Obj1__r" : {
          "records" : [{
                "attributes" : {"type" : "Test_Obj1__c", "referenceId" : "ref2"},
                "name" : "integr child"
            }]
        }
    }]
}

Request: https://mySandboxInstance.com/services/data/v37.0/composite/tree/Test_Obj1__c/ Authorization: OAuth security_token Content-Type: application/json

So, as you can see Test_Obj1__c is self-related and Child Relationship Name is "Test_Obj1".

I've tested with different self-related objects - it gives same result.

If I'm changing Test_Obj1__r to relation with different child object - it works fine.

Is there any way to insert nested self-related objects through one REST request?

2
  • build the self-referencing structure using the UI in SFDC, then use GET query to see how SFDC generates the result - that should be source for the POST
    – cropredy
    Commented Mar 11, 2017 at 8:23
  • Hi! Already tried that. Salesforce returned same structure: [ {"attributes":{"type":"Test_Obj1__c"}, "Name":"parent", "Test_Obj1__r":{ "records":[ {"attributes":{"type":"Test_Obj1__c"}, "Name":"child" } ] } }, {"attributes":{"type":"Test_Obj1__c",}, "Name":"child", } ] And deserialization resut is the same: "Cannot deserialize instance of <unknown> from FIELD_NAME value records or request may be missing a required field" Probably it is a bug, otherwise I don't know why Salesforce cannot deserealize its own serialized object.
    – Nikolai J
    Commented Mar 13, 2017 at 15:05

1 Answer 1

0

I believe you should try something like this:

{
"records" :[{
     "attributes" : {"type" : "Test_Obj1__c", "referenceId" : "ref1"},
     "name" : "integr parent"
    },

   {
     "attributes" : {"type" : "Test_Obj1__c", "referenceId" : "ref2"},
     "name" : "integr child",
     "Test_Obj1__r" : {
          "attributes" : {"type" : "Test_Obj1__c", "referenceId" : "ref1"}          
        }
    }]

}
1
  • Thank you for the answer, but it still fails, now with different error: "statusCode": "INVALID_FIELD", "message": "Cannot reference a foreign key field Test_Obj1__r.",
    – Nikolai J
    Commented Mar 9, 2017 at 10:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .