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?

  • 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 Mar 11 '17 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 Mar 13 '17 at 15:05
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"}          
        }
    }]

}
  • 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 Mar 9 '17 at 10:42

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.