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?