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
Chiel de Graaf.Chiel de Graaf. 

Ignore locked records in SOQL query

Hi all,

I've got an Apex class which updates a specific field in all cases every hour. A "problem" occurs with locked cases (cases open with agents).
The casefield is updated through the batchrun But when the case is opened by the agent before the batchrun and closed after the batchrun, the agent gets the errormessage that the case can't be saved because it was edited by .....

Is there a possibility in the Apex code to check in the query if a case is locked by an user, and if so exclude them from the queryresults and avoid the problem described above?

Regards
Chiel
Ekta Gupta 11Ekta Gupta 11
Hi Chiel,

You can add the lock to the records currently being edited but not sure if that's possible to track what all records are locked.

Another way to implement this is create a checkbox field (isEditied)  on Lead and set it true whenever Edit button is clicked and set it false whenever lead is saved.
And in your query you can exclude the Lead whose isEditied is True.
Chiel de Graaf.Chiel de Graaf.
Hi Ekta,

Thanks for your reply. If it can't be done solely in the Apex code, i will try the checkbox solution.


Regards
Chiel