+ Start a Discussion

Offline Mode Error : UNABLE_TO_LOCK_ROW

Hi All,


I have a requirement in which, whenever a contact is created or updated or deleted a trigger is executed which calls a Future class.


Future Class Logic: When a contact is created or updated, Rank is calculated for the contact based on the responses provided for certain fields. Calculated Rank and its corresponding Overall Rating are populated in their respective two fields (on Contact Object) and the contact is updated.

After updating the contacts Rank and Overall Rating, its account id is fetched, based on this all the contacts related to the fetched account are stored in a map. After storing all the related contacts in a map, a business logic is run based on which the contact with the best overall rating is identified and the overall rating of this best contact is updated on the corresponding account. 


This business logic needs to run in both online and offline (when synchronized from offline mode) mode. Entire business logic seems to be running fine but I get an apex exception mail in some scenarios stating:


" 'public static void Methodname(SET:Id)' : Update failed. First exception on row 0 with id 00xx000000xxxxxxxx; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: [] "


I am unable to identify the reason for this exception and how could I resolve it.


If anybody can help me in identifying the problem and the way to resolve it, I would appreciate it and be extremely thankful.


Waiting for the response.


Thanks in advance.