Visualforce works in synchronous mode and batch are asynchronous. You can use action method in visualforce page which can call a batch class from it. Perform dlete operation in that batch class. Note that will not get immediate response form it (Asynchronous call). If it is imortant to get responsethen each batch return its ID so by using actionpoller you can check for batch status by query.
Refer to link: https://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_asyncapexjob.htm
From your Apex controller, you would need to simply call Database.executeBatch(classname); to kick off the batch. Then in Visualforce, like Avillon stated, would need to poll for the status. Jason Venable aka tehnrd, has an excellent tutorial on a similar scenario, which even includes a progress bar: http://www.tehnrd.com/batch-apex-status-bar/
For writing the actual batch class, you'll want follow the examples here: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch_interface.htm
In the start method of the batch, you'll want to query for or generate the "scope" of records you'd like to delete.
In the execute method of the batch, you'll want to actually delete the scope of records.
Use the following batch code: *************************************
global class BatchDeleteAccounts implements Database.Batchable<sObject>{
global final string query;
global BatchDeleteAccounts(){
query = 'SELECT Id FROM Account; }
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query); }
global void execute(Database.BatchableContext BC,List<sObject> lst){
Database.delete(lst,false); }
global void finish(Database.BatchableContext BC){
} }
Put a Command Button on the VF page and create a method and in that method use the below code to call the batch: *******************************************************************************************************************************
public static void callTheBatch(){
BatchDeleteAccounts obj = new BatchDeleteAccounts(); Database.executebatch(obj); }
Refer to link: https://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_asyncapexjob.htm
In the start method of the batch, you'll want to query for or generate the "scope" of records you'd like to delete.
In the execute method of the batch, you'll want to actually delete the scope of records.
Here's another example I found on SSE where they are performing a batch delete: http://salesforce.stackexchange.com/questions/40351/i-am-executing-a-batch-apex-class-to-delete-the-records-from-recycle-bin-but-the
Use the following batch code:
*************************************
global class BatchDeleteAccounts implements Database.Batchable<sObject>{
global final string query;
global BatchDeleteAccounts(){
query = 'SELECT Id FROM Account;
}
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC,List<sObject> lst){
Database.delete(lst,false);
}
global void finish(Database.BatchableContext BC){
}
}
Put a Command Button on the VF page and create a method and in that method use the below code to call the batch:
*******************************************************************************************************************************
public static void callTheBatch(){
BatchDeleteAccounts obj = new BatchDeleteAccounts();
Database.executebatch(obj);
}
***************
Call this method from the VF page button..
Thanks,
Vijay