What exist
So I've custom Object called Credit Memo where I want to relate one Order and I want multiple OrderItem in the Relate List(Related Tab). I don't have Master-Detail relationship. Or by using lookup relationship I can only relate one record?
As it's easy to relate order as I only have to relate one so I can just search and select but I'm unable to figure out how to add Order Item using basic UI also because I don't have any option in a Related tab for adding the Order Item but the Related list still shows me Order Products Tab.
I want to achieve these using REST API too, I've tried composite tree but it fails(as I'm not doing it properly of course).
What I want
Is there any way of adding multiple child records to the custom object using REST API? Like Array of Id's to realte?
Sorry, Maybe I'm missing basics of how Salesforce work as I'm beginner.
UPDATE: I think my question is little confusing, so here's the simpler question I thought of - "How to link existing OrderItem to the custom object using REST API while creating the Record of that Custom object."
UPDATE
I was doing something horribly wrong, now I can relate OrderItems exactly the way I want by doing following.
Create Credit Memo
Go to OrderItem search and select Credit Memo Save
Do above for another OrderItem
By doing this I've two OrderItems in Credit Memo. So If I'm not wrong I've to do same via REST.
Insert Credit Memo via REST and save the response Id.
Update the existing OrderItem and set saved Credit Memo id to Credit Memo Lookup field.
Do above for another OrderItem.
But is there any way doing this opposite? Like while creating the Credit Memo how can I give both ID's and relate them? So it will minimize my update API calls
API Service I'm trying
Endpoint https:///services/data/v42.0/composite/tree/Credit_Memo__c/
Request Body (I know this is the dumbest way a one can think of)
{
"records":[
{"attributes":{"type":"Credit_Memo__c","referenceId":"ref1"},
"Name":"Test",
"Order_Product__c":{
"records":[
{"attributes":{"type":"OrderItem","referenceId":"ref2"},
"Id":"80229000000zltwAAA"}
]
}
}
]
}
Error
[
{
"message": "Cannot deserialize instance of reference from START_OBJECT value { or request may be missing a required field at [line:4, column:19]",
"errorCode": "JSON_PARSER_ERROR"
}
]