2

I am trying to insert records into the RelatedParty__c object in Salesforce. This object has two key fields:

  1. CompositeKey__c (External ID)
  2. Parent__c (Lookup to RelatedParty__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.

8
  • Can you post an example payload you try to use? Do you use it as "Parent__r.CompositeKey__c":"12354747" or as "Parent__r": {"CompositeKey__c" : "12354747"}? Commented Nov 29, 2024 at 13:11
  • Ive actually tried both examples that you have posted above, the first one returns no such column found and the second shows bad field names on insert/update call: Parent__r" Commented Nov 29, 2024 at 13:31
  • @kurunve I've added the payloads to the original post. Commented Nov 29, 2024 at 13:40
  • You can't POST to parent record fields. I think you have no choice but to use a Compsoite or Graph Composite call.. Commented Dec 1, 2024 at 5:49
  • @DavidCheng I'm actually using a PATCH request as its an UPSERT request. Commented Dec 2, 2024 at 12:07

1 Answer 1

0
+50

Assuming the parent record is already created in the database, the first payload attempt was mostly correct except for a syntax issue in parent field for the first block record. Instead of referencing the relationship field to be null in the parent record, you need to set the field Parent__c itself as null.

So this should normally work:

{ "allOrNone": true, "records": [ { "attributes": { "type": "RelatedParty__c" }, "Name": "Parent Company", "CompanyNumber__c": "542039532", "CompositeKey__c": "a0tPv00000EWh9pXXX;FR542039532", "Parent__c": null }, { "attributes": { "type": "RelatedParty__c" }, "Name": "Child Company", "CompanyNumber__c": "433699337", "CompositeKey__c": "a0tPv00000EWh9pXXX;FR433699337", "Parent__r": { "CompositeKey__c": "a0tPv00000EWh9pXXX;FR542039532" } } ] } 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.