1

I am writing a composite call to create products and add them to strandard Pricebook.

{
   "allOrNone":true,
   "collateSubrequests":false,
   "compositeRequest":[
      {
         "method":"GET",
         "referenceId":"refProductRecordType",
         "url":"/services/data/v56.0/query/?q=SELECT+id+FROM+RecordType+WHERE+SobjectType+='Product2'+AND+DeveloperName+='Product'"
      },
      {
         "method":"PATCH",
         "referenceId":"refProdList",
         "url":"/services/data/v56.0/composite/sobjects/Product2/External_Id__c",
         "body":{
            "allOrNone":true,
            "records":[
               {
                  "attributes":{
                     "type":"Product2",
                     "referenceId":"prod0"
                  },
                  "RecordTypeId":"@{refProductRecordType.records[0].Id}",
                  "Name":"product 1",
                  "External_Id__c":"12121",
                  "Description":"bla bla",
                  "IsActive":true
               }
            ]
         }
      },
      {
         "method":"GET",
         "referenceId":"refPricebook",
         "url":"/services/data/v56.0/query/?q=SELECT+id+FROM+Pricebook2+WHERE+Name+='Standard Price Book'+AND+IsStandard+=+true"
      },
      {
         "method":"POST",
         "referenceId":"refPbe",
         "url":"/services/data/v56.0/sobjects/PricebookEntry",
         "body":{
            "Pricebook2Id":"@{refPricebook.records[0].Id}",
            "Product2Id":"@{prod0.Id}",
            "UnitPrice":0.00,
            "IsActive":true
         }
      }
   ]
}

When I try executing this composite POST call, I get error :

{
   "body":[
      {
         "errorCode":"PROCESSING_HALTED",
         "message":"Could not find the referenced operation prod0"
      }
   ],
   "httpHeaders":{
      
   },
   "httpStatusCode":400,
   "referenceId":"refPbe"
} 

I am trying to access the referenceId "prod0", but not sure how to get it because it's kind of a nested reference.

Any help would be appreciated. Thanks

7
  • 1
    @identigral : here the question is about accessing PATCH request reference Id and your states GET request. If we observe this question, GET request Id is already used for pricebooks.
    – Rohit
    Commented Mar 6, 2023 at 17:19
  • There is no way for me to know if below answer solves the question. This is a serious limitation which will hamper the usability of Q&A on this site when anyone refers this in the future.
    – Rohit
    Commented Mar 8, 2023 at 15:48
  • @Rohit Is this because your answer wasn't accepted or...?
    – identigral
    Commented Mar 10, 2023 at 5:51
  • @identigral : Accepting answer is half part of the problem. The other half is if someone refers this question in the future , how will he/she come to know if below answer helps or not? If there are multiple answers , it will add to the confusion of which one is right? Last time I had politely asked the author to accept the answer if it helps but then one of the moderators termed it as "begging". :) In my opinion , moderators should have the right to accept the answer if the question author does not.
    – Rohit
    Commented Mar 10, 2023 at 6:00
  • @Rohit Keep answering, you'll get more acceptance. We've upvoted your answer, it's good.
    – identigral
    Commented Mar 10, 2023 at 16:39

1 Answer 1

1

This issue is seen since we cannot assign reference id to individual objects in request.

Reference Id is on sub-request level. To fix this , you need to set Product2Id as below. We refer to the 1st record of the PATCH sub request :

"Product2Id": "@{refProdList[0].Id}"

Here , refProdList refers to the PATCH request for Product2.

More info can be found in this documentation : https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/requests_composite.htm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .