I've been having trouble with a large system which uses lots of batch processes where I keep getting errors with UNABLE_TO_LOCK_ROW exceptions.

I read the locking Cheat Sheet here:


Which made me realise the cause of the problem. I had an Invoice Line Item custom object (of which there are hundreds of thousands) with a required lookup to a Term custom object (of which there are a handful). So, according to the cheat sheet, the fact that the lookup was required (i.e. "not configured to clear the value of this field if the lookup record is deleted.") meant that updating/inserting the Invoice Line Items was locking the Term, and thus the batch processes were able to clash on trying to obtain locks for the Terms.

So, changing over to not make the lookup a required field seems to have solved the problem with lock contention.

My question (finally!) is: Can adding a validation rule cause SF to lock a record? i.e. having made the lookup from Invoice Line Item to Term optional rather than required at the field level, I'd like to add a validation rule requiring it again. I need that field to be filled in for data integrity reasons. But I'm worried that it might re-introduce the locking problem - and since locking problems are hard to test, I was hoping someone with experience could let me know what the expected behaviour is?

  • The VR on Term will only execute if the Term is undergoing DML. Does the batch process update the Term? Do RSF's execute on Term ? – cropredy Apr 25 '16 at 13:32
  • Maybe I wasn't clear, I'm talking about putting a validation rule on Invoice Line Item, requiring that the lookup field to Term is populated. My worry is that this would do roughly the same thing as just making the Term field required - so might result in DML on Invoice Line Item locking Term. – Aidan Apr 25 '16 at 16:15
  • 1
    Hmm -- ISBLANK(Invoice_line_item__c.Term__c) should not involve locking the Term__c – cropredy Apr 25 '16 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.