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
James East 5James East 5 

Apex method - record locking

We are experiencing record locking issues when inserting data into SF and only since the day after Summer 16.. 
  • When we insert the records we execute an APEX method which builds 2 rows to be inserted;
  • the first insert is executed and the record id is retrieved -  
  • once this has occurred we create the second row and set it's related id to be the retrieved records id
  • then complete the 2nd insert.
 Both inserts occur in the same APEX method therefore within the same transaction.
 In addition to the above both the records created in the APEX method mentioned above are children of a record created within another APEX method but that initial insert is completed as part of a separate operation
 The sequence of events is as follows:
1.  Create parent record and retrieve it's record id as part of APEX method1
2.  Create 1st child record, insert the record and retrieve its record id, create 2nd child record assigning it's related record id to the first child record and perform the insert as part of a second APEX method; the second APEX method is failing with a row locking exception.
 
Additional information:
There are approx 19 roll-up summaries on the parent record, there are approx 24 roll-up summaries on each of the child lines.
 
There are approx 10 triggers associated with the parent and child records
 
In the test scenario that is leading to the locking exception we attempt multiple concurrent write requests, those which complete take 0.6 seconds, those which fail take over 9.5 seconds which as far as I am aware violates one of the governor limits however I cannot determine why the writes should be taking this long, the test scenario will attempt approx 586 writes (which should generate 1172 child lines), it must be stated that the 586 writes include numerous concurrent write requests as part of the external process which gathers the data and attempts to push it to SF.
 
Any thoughts and advice as to why this has suddnely reared its head upon Summer 16 would be amazing.

yours nervoulsy waiting some more experianced advice.
James
 
deepak balur 19deepak balur 19
James, you need to do some cleanup. Why are there 10 triggers for the same object? You should have only 1 trigger  per object which should handle all the DML operations.
Check your WF's and ProcessBuilders. Are there updates happening to your parent and child records. Map out the flow that should happen. Turn your debug logs on and see what is happening. See if some logic can be performed asynchronously. Without any code, it is hard for the commuity to guide further but I have given the general approach to take.