I am trying to insert records into the RelatedParty__c object in Salesforce. This object has two key fields:
CompositeKey__c(External ID)Parent__c(Lookup toRelatedParty__c).
My JSON payload contains records referencing other records in the same payload. For example:
- Company 123 is the parent of Company ABC.
- The records are ordered so dependencies appear higher (e.g., Company 123 is inserted before Company ABC).
To set the Parent__c lookup, I use Parent__r.CompositeKey__c in the JSON payload for Company ABC to reference Company 123. However, Salesforce returns this error:
No such column 'Parent__r.CompositeKey__c' on sobject of type RelatedParty__c.
I also tried using the relationship name Child_Related_Parties__r.CompositeKey__c (from the Parent__c field's details page), but this didn't work either.
I would prefer not to use the Composite API due to its 25-record limit or the Bulk API due to its asynchronous nature.
Is there a way to achieve this with a single synchronous API call?
Here are examples of the payloads I've used:
{ "allOrNone": true, "records": [ { "attributes": { "type": "RelatedParty__c" }, "Name": "Parent Company", "CompanyNumber__c": "542039532", "CompositeKey__c": "a0tPv00000EWh9pXXX;FR542039532", "Parent__r": null }, { "attributes": { "type": "RelatedParty__c" }, "Name": "Child Company", "CompanyNumber__c": "433699337", "CompositeKey__c": "a0tPv00000EWh9pXXX;FR433699337", "Parent__r": { "CompositeKey__c": "a0tPv00000EWh9pXXX;FR542039532" } } ] } Second attempt
{ "allOrNone": true, "records": [ { "attributes": { "type": "RelatedParty__c" }, "Name": "Parent Company", "CompanyNumber__c": "542039532", "CompositeKey__c": "a0tPv00000EWh9pXXX;FR542039532", "Parent__r.CompositeKey__c": null }, { "attributes": { "type": "RelatedParty__c" }, "Name": "Child Company", "CompanyNumber__c": "433699337", "CompositeKey__c": "a0tPv00000EWh9pXXX;FR433699337", "Parent__r.CompositeKey__c": "a0tPv00000EWh9pXXX;FR542039532" } ] } Edit: I have found using BULK API and using the column titled Parent__r.CompositeKey__c works.
"Parent__r.CompositeKey__c":"12354747"or as"Parent__r": {"CompositeKey__c" : "12354747"}?bad field names on insert/update call: Parent__r"