4

In my setup, Leads can have multiple Affiliates (custom object Affiliate__c), which is implemented through a child relationship and where each Affiliate consists of a name and the two related objects: The affiliated Lead and the affiliating Account.

When trying to create a Lead together with an (existing) Affiliate using the Composite Tree Resource and the following payload, it fails with a Cannot reference a foreign key field Account__r.

{
    "records": [
        {
            "attributes": {
                "type": "Lead",
                "referenceId": "ref1"
            },
            "LastName": "Doe",
            "Lead_External_Id": "L1",
            "Affiliates__r": {
                "records": [
                    {
                        "attributes": {
                            "type": "Affiliate__c",
                            "referenceId": "ref2"
                        },
                        "Name": "First Affiliation",
                        "Account__r": {
                            "Id": "123456"
                        }
                    }
                ]
            }
        }
    ]
}

However, if I use the Composite Resource with the following payload, it works fine:

{
    "compositeRequest": [
        {
            "method": "POST",
            "url": "/services/data/v43.0/sobjects/Lead",
            "referenceId": "ref1",
            "body": {
                "LastName": "Doe",
                "Lead_External_Id": "L1"
            }
        },
        {
            "method": "POST",
            "url": "/services/data/v43.0/sobjects/Affiliate__c",
            "referenceId": "ref2",
            "body": {
                "Name": "First Affiliation",
                "Lead__r": {
                    "Lead_External_Id": "L1"
                },
                "Account__r": {
                    "Id": "123456"
                }
            }
        }       
    ]
}

What am I doing wrong when using the Composite Tree Resource? Is this resource not capable of creating a child relationship with a reference to another object?

0

Maybe it is too late to answer, but you are right, Composite Tree resource must have only one parent object and their child within the tree.

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.