I have a VF page that has been in production for a few weeks; this error was seen for the first time today. I know that locking errors can be sporadic, and the admin couldn't reproduce (logged in as the user). I'm trying to figure out if I need to make any adjustments to my code to prevent this in the future.
The error occurred during a controller method invocation; the method is called as an Action method on a CommandButton. The method runs a query of a custom object, and for each record found, creates a Task and creates a Custom object to be updated; after the loop I insert the list of tasks and update the list of custom objects. The error occurred during the Task Insert.
I've reviewed the code, and tried to eliminate possible causes:
- The insert is the first place DML is occuring in the method.
- The SOQL in the method does not use
- There is one Trigger on Task, but it is an update trigger only, so it is not running.
- Task is not an M-D child, so no standard Rollups are involved.
- We use DLRS in the org, but I've confirmed there are no rollups on Task.
- There are no Workflows or Process Builder processes on Task.
In short, I can't find any "side-effect" DML, so I have to believe that it was the insert itself that caused the error. That doesn't make sense since an Insert should not need to lock records. The tasks I am inserting have both
whoid populated, as well as a custom lookup field to a custom object; does the system lock those related objects for any reason? Any other causes I've overlooked?