Not only that, what if you need to perform further data integrity tasks before removing the records?
Mass updating, inserting and other similar scenarios like this can be more conveniently handled with force.com's Batch Apex. With Batch Apex you can now build complex, long-running processes on the platform. This feature is very useful for time to time data cleansing, archiving or data quality improvement operations.
One thing that you need to consider is that you should trigger the batch job using Apex code only and force.com by default does not provide scheduling feature your batchable Apex classes. In order to do that you need to write Apex class that implements a "Schedulable" interface.
The following example shows how you can utilize the model to mass delete records of any object in force.com platform.
In order to develop your Batch Apex, you need to create a new Apex class which extends "Database.Batchable" interface.
This interface demands for three methods to be implemented:
The "finish" method is called once all the batches are processed. You can use this method to carry out any post-processing operation such as sending out an email confirmation on the status of the batch operation.
Let's take a closer look at each of these methods:
Alternatively you can use the iterable when you need to create a complex scope for your batch job.
In this method I have utilized the Apex email library to send a notification to the owner of the batch job (whoever triggered the job in the first place).
Now, let's put it all together:
Now let's write the code in Apex to run the class and test it:
As it is apparent, now you can run the batch job from within your Visualforce pages, triggers (with caution), etc.
For governing limit and best practices documentation you can refer to the Apex Developer Guide.