
It is possible to hard delete using DataBase.emptyRecycleBin method in the Batch class. Create a sample Batch class as mentioned below and use DataBase.emptyRecycleBin method in the Batch class.
Full Answer
What is a batch Class in Salesforce?
A Batch class allows you to define a single job that can be broken up into manageable chunks that will be processed separately. When to use Batch Apex One example is if you need to make a field update to every Account in your organization. If you have 10,001 Account records in your org, this is impossible without some way of breaking it up.
How to schedule a batch to run daily in Salesforce?
In addition, have the batch class implement Schedulable and add a second execute method, like so You can then schedule this batch to run daily within Salesforce setup - there's a button in the Apex Classes section to do so.
What is the difference between execute and finish methods in Salesforce?
2) Execute Method performs operation which we want to perform on the records fetched from start method. 3) Finish method executes after all batches are processed. Use this method to send confirmation email notifications. Please check the below code for delete Accounts, Contacts and Opportunities records using single batch class.
How to delete a lot of Records in a batch file?
You can just run an anonymous script if "a lot of records" is less than 10k. If you have more records than that, I recommend plugging the above SOQL into Data Loader. Export all matching records, then upload the resulting CSV in a delete job. If you're dead set on writing a batch, you can create a QueryLocator with that query.

How do I mass delete records in Salesforce?
From Setup, enter Mass Delete Records in the Quick Find box, then select Mass Delete Records and click the link for the type of record to delete. Review the information that is deleted with the records. Specify conditions that the selected items must match, for example, “State equals California.”
How do I delete a batch class in Salesforce?
1. Go to Monitor --> Jobs --> Scheduled Jobs. 2. Delete the appropriate scheduled job.
How do I delete more than 10000 records in Salesforce?
A single transaction can only update up to 10,000 records. This is a global governor limit, not specific to flows. You cannot work around it, and you will have to split it into multiple transactions. Your best bet would be to use a batch Apex class if you wanted to delete this many records.
How do I delete records from Apex Salesforce?
With the developer console, you can enter Apex code directly into your Salesforce to enable you to delete records. To use this method, simply open the editor window and enter code by changing MyObect to the object you will like to delete from. For example: delete[SELECT id FROM MyObject];
How do you hard delete records in Salesforce using data loader?
Required Editions and User PermissionsOpen the Data Loader.Click Insert, Update, Upsert, Delete, or Hard Delete. ... Enter your Salesforce username and password. ... Choose an object. ... To select your CSV file, click Browse. ... Click Next.More items...
How do you delete hard records?
Hard delete is done by using DataBase. emptyRecycleBin method in the Batch class. Create a sample Batch class as mentioned below and use DataBase. emptyRecycleBin method in the Batch class.
How do I delete more than 50000 records in Salesforce?
To delete more than 50,000 records, you can use the DataLoader program....This file can now be used to delete those records from the org:Tab Data - click on Delete;Eventually enter again in your org;choose the From File radio button;Map the field;Delete all!
How do you mass delete records from list view?
In the List View, we can select an item and then press the Bulk Delete button. The documents are then removed from the organization. This is for Lightning; If we want to use it as a classic, we have to use button JS.
How do I delete old data in Salesforce?
Navigate to Setup. Enter Delete into the 'Quick Find' box and select Mass Delete Records from the results. Select a type of Record that you wish to delete, such as Accounts. Review the notes which state the records that will be deleted.
Can we delete record in Salesforce?
After you persist records in the database, you can delete those records using the delete operation. Deleted records aren't deleted permanently from Salesforce, but they are placed in the Recycle Bin for 15 days from where they can be restored. Restoring deleted records is covered in a later section.
How do I delete multiple records from a custom object in Salesforce?
It is not possible to delete multiple records at once. Now the user can simply select all the required records and hit the “Delete Row” button to delete multiple records using a single click of the Delete button.
How many types of SObjects can you combine in DML?
You can combine up to 10 types of SObject in one list for DML as long as they are grouped by type. See this post by Jesse Altman for more color on that.
Can you call batches in a chain?
Another option is to call batches in chain, so you can get advantage of Database.queryLocator that is able to return more records than Iterator. On each chain you can query the object you want to remove and delete it. You would be able to set different scopeSize for each one as well if this is required.
