function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sumant KuchipudiSumant Kuchipudi 

Record Currently Unavailable: The record you are attempting to edit... getting this issue

First I directly trying to update records but got "UNABLE_TO_LOCK_ROW on updating records.." issue, then I use "FOR UPDATE" keyword on select query then I'm getting this error from select statement.
Record Currently Unavailable: The record you are attempting to edit, or one of its related records, is currently being modified by another user. Please try again
I have no clue how to avoid this issue, is there anything I'm missing? please advise.
 
ANUTEJANUTEJ (Salesforce Developers) 
Hi Sumanth,

Could you please elaborate on the scenario you are implementing and where you are facing this issue while implementation to check further.

Please let me know these details to check further.

Regards,
Anutej
Sumant KuchipudiSumant Kuchipudi
Hi Anutej, thanks for looking into the issue.
Here are the details...
I have a process which is searching Contact by set of ids and setting flags to the records.
contactToUpdate = [SELECT id FROM Contact where id in :idset];
                    if (contactToUpdate != null && contactToUpdate.size()>0){
                        for (Contact con: contactToUpdate){
                            con.registered__c=true;
                        }
                    }
                    update contactToUpdate;
This process failed with "UNABLE_TO_LOCK_ROW on updating records.." since there is another process which runs simultaniously which is causing I guess.
and then I used "FOR UPDATE" to the search soql but again failed with "Record Currently Unavailable: The record you are attempting to edit, or one of its related records, is currently being modified by another user. Please try again".
contactToUpdate = [SELECT id FROM Contact where id in :idset FOR UPDATE];
                    if (contactToUpdate != null && contactToUpdate.size()>0){
                        for (Contact con: contactToUpdate){
                            con.registered__c=true;
                        }
                    }
                    update contactToUpdate;