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

Problem creating parent + child object in the same transaction



We are seeing some strange behaviour with a VF controller we're trying to deploy from a Sandbox org to production.  In our org we have a parent-child relationship (lookup) between two objects.  A method in the controller class creates a record of the parent object, and then creates a child object record, linking it to the new parent record (newChildRec.Parent__c = parentRec.Id ).  This is all in one method, so presumably it's all taking place in a single transaction.


So this works fine in the sandbox, and the covering testMethod works fine too - both parent and child records are created no problem.


But when we try to deploy to the production org, the testMethod fails, saying (roughly) "Unable to obtain exclusive access to the record" (UNABLE_TO_LOCK_ROW) when trying to create the CHILD record.  Why would this be?  I do understand that when you create a child object record, the system locks the parent record.  But how come this would work on the sandbox but not when we try to deploy to production?  Wouldn't the fact that this is within the same transaction cause this failure to NOT happen?  Could it have to do with API versions, perhaps?  The controller in question is 15.0, and it is being deployed using Eclipse with plugin version 15.0.    The sandbox is on Summer '09 whereas the prod org is of course still on Spring '09, in case that makes a difference.


Can someone advise, by any chance?  



Rajesh ShahRajesh Shah

Hi Phils,


Were you able to find a solution to the above problem?