+ Start a Discussion
Kumar_ShahKumar_Shah 

System.QueryException: Record Currently Unavailable exception

How to avoid the following exception. I added FOR UPDATE in SOQL statement but it still throws the following exception.

Question 1: As per the documentation, if the operation takes more than 10 seconds, it will throw this error. In my scenario, it takes less than 10 seconds but still throws an error.

Question 2: Let us say, the operation takes more than 10 seconds, how we can avoid this error?

Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY
System.QueryException: 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

Thanks,
Venkata GangulaVenkata Gangula
Hi Kumar

for Question 2: you need to proceed by using Asynchronous Apex types (Future method, Batch Apex, Scheduled Apex, Queueable Apex).

An asynchronous process is a process or function that executes a task "in the background" without the user having to wait for the task to finish.

The benefits of  using Asynchronous Apex is , it provides us with high governor and execution limits (as it runs processes in a seperate thread) leading to efficiency.

for your reference and understanding, go through the explanation by accessing this URL or module in Trailhead : Asynchronous Apex | Salesforce Trailhead.

If you find the answer as helpful , mark it as solution and best answer so that other users with same issue will be benefitted.
sachinarorasfsachinarorasf
Hi Kumar,
 

This basically happens when there is a conflicting modification being done by another user/process on a particular record that you are trying to access. 
Mostly it will happen when any kind of batch process is running in the background and locked the particular record you are trying to access(in your case Account). To get rid of this problem, you would need to check if there are any scheduled apex classes
running in the background on Accounts/Cases and see if there is anything you can do to optimize the code to avoid conflicting behavior.

I hope you find the above solution helpful. If it does, please mark it as Best Answer to help others too.

Thanks and Regards,
Sachin Arora
www.sachinsf.com