+ Start a Discussion
Sreenivasulu AdipudiSreenivasulu Adipudi 

Handle browser refresh on Visualforce page

Hi Everyone,

I created a Visualforce page with a Delete All button. On click of the button, it will call the controller method and the controller method executes a batch class that will delete all the records from the object. 
Everything working as expected but if we click browser refresh button or F5 key while the deletion is in-progress then the batch class is re-initiating. 
How to stop the browser refresh.

My code as follows :

Viusalforce page :
<apex:page standardController = "Account" extensions="DeleteRecordsExtn">
    <apex:commandbutton label="DeleteAll" action="{!doDelete}"/>

Controller method :
public void doDelete() {
    DeleteRecordsBatch delBatch = new DeleteRecordsBatch();

Batch class :
public class DeleteRecordsBatch implements Database.Batchable<sobject>{

public Database.QueryLocator start(Database.BatchableContext BC){
    return Database.getQueryLocator('SELECT Id FROM Account');
public void execute(Database.BatchableContext BC, List<SObject> lstRecords){
    Database.delete(lstRecords, false);
public void finish(Database.BatchableContext BC){

Can anyone please help me in this scenario.
Best Answer chosen by Sreenivasulu Adipudi
if the scenario  is just stop the browser refrssh or f5 functionality, you have javascript or jquery code available, you can use those code  either in the stattic resources or  in the within the script tag in vf code. so that it can be stopped .