1

I am trying to make 100 concurrent API calls for creating an Object Example1. And this Example1 object is having Master-Detail Relationship with Parent Example1 Object. I am using same ParentExample1Id for all these 100 APIs as per the requirement. And after some success calls I am stuck at the error

{"message":"unable to obtain exclusive access to this record","errorCode":"UNABLE_TO_LOCK_ROW","fields":[]}

How can I successfully complete all the 100 API calls without locking issue? Please help me out of this

1 Answer 1

1

SObject Tree creates one or more sObject trees with root records of the specified type. An sObject tree is a collection of nested, parent-child records with a single root record.

In the request data, you supply the record hierarchies, required and optional field values, each record’s type, and a reference ID for each record.

Upon success, the response contains the IDs of the created records. If an error occurs while creating a record, the entire request fails. In this case, the response contains only the reference ID of the record that caused the error and the error information.

Sample request body for Account and contact relationship:

{
  "records": [
    {
      "attributes": {
        "type": "Account",
        "referenceId": "ref1"
      },
      "name": "SampleAccount",
      "phone": "1234567890",
      "website": "www.salesforce.com",
      "numberOfEmployees": "100",
      "industry": "Banking",
      "Contacts": {
        "records": [
          {
            "attributes": {
              "type": "Contact",
              "referenceId": "ref2"
            },
            "lastname": "Smith",
            "title": "President",
            "email": "[email protected]"
          },
          {
            "attributes": {
              "type": "Contact",
              "referenceId": "ref3"
            },
            "lastname": "Evans",
            "title": "Vice President",
            "email": "[email protected]"
          }
        ]
      }
    }
  ]
}
8
  • 1
    ok.. But how can i avoid locking issue and succesfully complete 100 concurrent calls at once. I have to make it as seperate calls itself. Not as a composite call
    – Seena V P
    Nov 6, 2017 at 9:20
  • 1
    You are encountering that error because Salesforce locks master record whenever you edit/insert child record so you can't avoid that because you are running concurrent call. One resolution is create record with batch size 1, another solution is process record creation in Serial mode. Here is detailed explanation help.salesforce.com/articleView?id=000229525&type=1
    – Himanshu
    Nov 6, 2017 at 9:30
  • Ok.. Here i am not using Bulk API concept and sending APIs seperately at the same time. Can you please tell me how can I set the batch size to 1 here?
    – Seena V P
    Nov 6, 2017 at 9:35
  • how are you inserting records using any third party?
    – Himanshu
    Nov 6, 2017 at 9:43
  • 1
    I think you are in wrong direction. My solution is if you are doing dev. Salesforce.com doesn't recommend stress testing their servers. They do that themselves, and they look at the larger picture than just any one organization. You should read this salesforce.stackexchange.com/questions/16213/…
    – Himanshu
    Nov 6, 2017 at 9:54

You must log in to answer this question.

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