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
DevelopersDevelopers 

How to restrict the users for accessing the same VF page at a time?

Hi,

 

We have developed one customized VF page for executing the Batch apex. Now, we want to restrict the users accessing the same at a time. Means, if one user accessing the page, at the same time, if any one wants to access the same page, we need show the message saying that, the page is accessed by so and so user. 

 

How to identify that which user access the page first and how to restrict the other users, for using the same page which is accessed by the other one.

 

Kindly give me any suggestions for this. Thanks in advance.

 

Regards,

Phanikumar

SeAlVaSeAlVa

Two ideas.

 

1st. Create a Custom Setting and set it to true when the batch starts, and to false when the batch stops, so you check for that before running the batch.

 

2nd, Create a Custom Setting that stores the user that is inside your VF. This setting will be populated from your VF, on the constructor and with an apex:actionPoller triggered each.... minute. so before getting in the VF, you check the user, the timestamp (if it hasn't been refreshed 3 minutes ago, means that the user quit).

 

Both have their issues, for example, if an user lost the connection, and recovers it in few minutes, 2nd option might be compromised.

For 1st option, you might want to take current timestamp to prevent concurrency problems.

 

Hope this helps.

 

Regards