I have a batch process which updates Accounts and sometimes when i run this batch i get the error.
UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record
I did read through Mohit's answer on why this is happening here Can anybody explain the UNABLE_TO_LOCK_ROW error?
Based on this article http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_locking_statements.htm
Using the FOR UPDATE
locks the whole set of records. The question i have is that is it a good practice to do this on a batch process, as the batch process could run for sometime and till then all the records would be locked.
In my batch process i am querying for all the accounts in the start method and in the execute method i am checking for certain conditions deciding if these records need to be updated or not. I cant perform these checks using WHERE clause as it depends on combination of factors dependent on other objects.