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
KiranNaiduKiranNaidu 

Issue while using composite tree API in workbench for Invoice and InvoiceLines

In the workbench Rest Explorer for Salesforce Billing App.I used  Rest API with post method "/services/data/v49.0/composite/tree/blng__Invoice__c".
below is the JSON request body

{
"records" :[
    {
        "attributes" : {
            "type" : "blng__Invoice__c",
            "referenceId" : "ref1"
        },
    //InvoiceFields 
        "blng__Account__c": "0012y000006zj8uAAA",
        
    "InvoiceInvoiceLines" : {
        "records" : [
        {
                "attributes" : {
                    "type" : "blng__InvoiceLine__c",
                    "referenceId" : "ref2"
                    },
                "Name": "Test Product"
         },
         {         
                "attributes" : {
                    "type" : "blng__InvoiceLine__c",
                    "referenceId" : "ref3"
                    },
                    
                "Name": "Test Product"
         }]
      }
    }]
}

I get the below error "INVALID_FIELD
message: No such column 'InvoiceInvoiceLines' on sobject of type blng__Invoice__c
errorCode: INVALID_FIELD
"
Here "InvoiceInvoiceLines" is the Child relationship name.
Can someone help me in undestanding this issue. 
Best Answer chosen by KiranNaidu
AnudeepAnudeep (Salesforce Developers) 
Can you write a relationship query with InvoiceInvoiceLines as a relationship name querying on blng__Invoice__c? Your composite tree structure looks fine. Double check on the relationship name. Here is an example of request body that uses one SObject tree to create a single Account record along with two child Contact records:
 
{
"records" :[
  {
    "attributes" : {"type" : "Account", "referenceId" : "ref1"},
    "name" : "SampleAccountWithContacts",
    "phone" : "1234567890",
    "website" : "www.salesforce.com",
    "numberOfEmployees" : "100",
    "industry" : "Banking",
    "Contacts" : {
      "records" : [{
         "attributes" : {"type" : "Contact", "referenceId" : "ref2"},
         "lastname" : "Smith",
         "Title" : "President",
         "email" : "sample@salesforce.com"
       },{
         "attributes" : {"type" : "Contact", "referenceId" : "ref3"},
         "lastname" : "Evans",
         "title" : "Vice President",
         "email" : "sample@salesforce.com"
       }]
     }
  }]
}

Let me know if it helps. If it does, please mark this answer as Best. It may help others in the community. Thank You!

All Answers

AnudeepAnudeep (Salesforce Developers) 
Can you write a relationship query with InvoiceInvoiceLines as a relationship name querying on blng__Invoice__c? Your composite tree structure looks fine. Double check on the relationship name. Here is an example of request body that uses one SObject tree to create a single Account record along with two child Contact records:
 
{
"records" :[
  {
    "attributes" : {"type" : "Account", "referenceId" : "ref1"},
    "name" : "SampleAccountWithContacts",
    "phone" : "1234567890",
    "website" : "www.salesforce.com",
    "numberOfEmployees" : "100",
    "industry" : "Banking",
    "Contacts" : {
      "records" : [{
         "attributes" : {"type" : "Contact", "referenceId" : "ref2"},
         "lastname" : "Smith",
         "Title" : "President",
         "email" : "sample@salesforce.com"
       },{
         "attributes" : {"type" : "Contact", "referenceId" : "ref3"},
         "lastname" : "Evans",
         "title" : "Vice President",
         "email" : "sample@salesforce.com"
       }]
     }
  }]
}

Let me know if it helps. If it does, please mark this answer as Best. It may help others in the community. Thank You!
This was selected as the best answer
Jorge Romero 16Jorge Romero 16
Hi, 

You have to use the name of the relationship and also add the __r. Example:

{
"records" :[
    {
        "attributes" : {
            "type" : "blng__Invoice__c",
            "referenceId" : "ref1"
        },
    //InvoiceFields 
        "blng__Account__c": "0012y000006zj8uAAA",
        
    "InvoiceInvoiceLines__r" : {
        "records" : [
        {
                "attributes" : {
                    "type" : "blng__InvoiceLine__c",
                    "referenceId" : "ref2"
                    },
                "Name": "Test Product"
         },
         {         
                "attributes" : {
                    "type" : "blng__InvoiceLine__c",
                    "referenceId" : "ref3"
                    },
                    
                "Name": "Test Product"
         }]
      }
    }]
}