4

I am trying to update a group of records satisfying certain conditions it was giving me Error which says:-

UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record or 10 records

so I tried to use FOR UPDATE clause for this query but now it is giving me this error:-

SObject type does not allow locking rows.

Here is the query I am using:

Select Id from user where lmscons__Cornerstone_ID__c != NULL AND 
lmscons__CFS_Status__c = 'Active' AND Checked_Today__c = true LIMIT 10 FOR UPDATE
  • 3
    The error usually occurs when multiple users are trying to update the same record, or there might be some triggers or @future jobs updating the record. Please share your query. Do you use FOR UPDATE in your query? – Mohit Arora Aug 1 '17 at 5:10
  • 2
    I don't think you are allowed to lock the user records. Rest most of the objects allow this, but not user may be. I haven't been able to find a documentation on this. – Mohit Arora Aug 1 '17 at 8:17
  • @MohitArora If I execute this query in start method of the batch class will I get an exclusive access to the records? – Ishan Aug 2 '17 at 7:43
  • Well that would be a hit and trial. – Mohit Arora Aug 2 '17 at 8:46
  • This is very interesting. I would expect some property in SObjectType.describe like "Lockable" to understand which SObject types are lockable but there is none – Patlatus May 4 '18 at 14:28
0

This is specific behavior for User object. For any other standard or custom object, FOR UPDATE Keyword is working while for User it is not.

This might be drawback of Salesforce platform that there is no list of object types available for FOR UPDATE keyword.

I suggest to open an idea to elaborate documentation to provide list of object types which support FOR UPDATE keyword. I have just opened a one, so vote for it to persuade Salesforce implement this.

Also I would expect some property in SObjectType Describe like "Lockable" to understand if this object type supports FOR UPDATE keyword or not.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.