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
tola2278tola2278 

Batch Apex Question

Hi,

 

Basically i have a task to create a batch which works if User select Startdate and enddate of data to be deleted please guide me how can i start 

Bhawani SharmaBhawani Sharma
You can create a VF page for capture the user input.
From your controller, you can call a batch process using database.executeBatch(Batch Class Instance) statement.

in start method of batch, fetch all teh records using SOQL query like
Select Id from Account where CreatedDate > StarteDate and CreatedDate < endDate

in batch's execute method, simply delete these records using database.delete(scope, false) statement.
dphilldphill

In a batch class, you can specify a constructor.  You can have this constructor take parameters in which to use when the execute method calls a query to execute the batch over.