2

I would like to create Asset hierachy with a single REST API call, providing root Asset and his child Assets (Documentation). I can't do this because it seems that Asset.ParentId field doesn't have relationship name

enter image description here

I tried to guess relationship name but with no success.

Here is my sample request body:

{
    "records": [{
        "attributes": {"type": "Asset", "referenceId" : "root"},
        "Name": "Root Device",
        "AccountId": "someId",
        "ChildAssets": {
            "records": [{
                 "attributes": {"type": "Asset", "referenceId" : "device1"},
                 "Name": "Device Nested 1",
                 "AccountId": "someId"
            },{
                 "attributes": {"type": "Asset", "referenceId" : "device2"},
                 "Name": "Device Nested 2",
                 "AccountId": "someId"
            }]
        }
    }]
}

Do you have any idea how this can be achieved? Is there any option besides creating new custom field and using it in REST api call to build hierarchy?

  • 1
    Just as a note for others: Asset Hierarchies were added in Spring '16 (API Version 36). – Derek F Mar 4 '16 at 16:12
  • 1
    this is a great question... when I do a describe on Asset and examine the getChildRelationships() - the relationship to child asset displays with name = null; same when using Eclipse Schema explorer. You may have to use an external ID to make the association or multiple REST calls. I tried guessing as did you that the relationship name followed SFDC conventions and was simply ChildAssets or Assets - but that was an invalid type. I don't think SFDC as of V36 is exposing this relationship name yet. – cropredy Mar 6 '16 at 7:16
1

I was going through my question on Salesforce StackExchange and got here to this unanswered question.

Looks like I was trying to use it too early (just after release in API 36) and it wasn't yet available, even though the field was there (but as you can see in the question it didn't have ChildRelationshipName in the Schema).

8 releases later I checked it and it's there with the exactly same name that I was expecting 2,5 years ago:

enter image description here

I don't know exactly in which api version it was added but it's there and the code sample above works. hurray!

  • 1
    You should mark this as the answer – cropredy Mar 24 at 5:11
  • Thanks @cropredy , it's strange to accept my own answer to my question without any upvotes. But since I got one I did it :) – neff Mar 27 at 9:51

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.