function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mayank AcharyaMayank Acharya 

What are the implication for the "POST" rest call on child object when it's in mater detail relationship

Hi Devs,

I have 2 custom objects

1) order having  fields -> orderId, pobox, emailaddress etc. some of these are required fields.
2) item refer to order in master detail relationship, order was created first so assuming that will be master.

item having fields -> itemid, category, orderId , Order__c

WHen I make post call on item without any fields of Order in payload it return exception saying "message": "Required fields are missing: [Order__c]"

My questions is  do I need to pass all fields of "order" object when I do POST on  item object  or just those which  are required once under order object field definition? Or Is there any other way to refence the order object  while making post call to item object?  

 

Syed Insha Jawaid 2Syed Insha Jawaid 2
Hi Mayank

I am assuming that you are trying to insert "Item'' record in Salesforce which is a child of "Order" object. If that's the case then the request body for item should have the "Order" record Id in it since it is a master-detail relation.

For example : If the system has an order "O-001" with salesforce Id "XXXXX.." and you wish to insert item under this order then the paylod should be something similar to this :

{
"Category__c" : "XYZ", //If it is a picklist then any of the desired value to be passed.
"Order__c" : "XXXXX.." //The recordId of the order under which this item has to be inserted.
.....
Mayank AcharyaMayank Acharya

Hi Syed,

Thanks but I am not clear on what would be  record Id  or salesforceid for "Order"  object?
I haven't created any record type for the order or item custom objects as I didn't see the need of it. 
It seems it is implied this problem can not be solved without creating record type ?

By the way, This is how specs looks like;

Order custom object:
value:
  orderNo__c: "223z3a55b780"   # required field
  currencyCode__c: "USD"
  subTotal__c: 41.5
  email:__c "test0@test.com".    #required field

Item custom object:
value:
  id__c: "2280"
  category__c: "snacks"
  quantity__c: 3
  orderId__c: "223z3a55b780" 
  order__c:  "18 char alphanumeric "    #say  a0XXXXXXYZQAW

I tried with  18char SF id for order 223z3a55b780 but it still return the error;

"message": "Order: id value of incorrect type: a0XXXXXXYZQAW FIELD_INTEGRITY_EXCEPTION"

I am passing  SF id of the record as json string seems like salesforce api is not liking it.

Mayank AcharyaMayank Acharya
My bad for some typo just to clarify , I found the salesforce id for that record but that doesn't work because of data type. I don't have any record id for the record as I didn't create any record type.
Syed Insha Jawaid 2Syed Insha Jawaid 2
Each record stored in Salesforce has a record Id associated with it.
If you any Order record in Salesforce; go to the detail page of the record. The URL will have the id which is the record Id that needs to be passed while creating Item record in Salesforce.

For example: If I access Account record in Salesforce this is how the URL looks : 
https:<Your_Domain>>.lightning.force.com/lightning/r/Account/001XXXXXXXXXX/view.

Record Id is 001XXXXXXXXXX.