It is possible that we have been in a situation where we needed to quickly mass delete data from Salesforce, such as accounts, contacts, leads, or any other standard/custom objects previously imported incorrectly or objects that we want to delete from Salesforce forever.
It’s worth noting that Salesforce has its tool for deleting large amounts of data. This built-in tool is mainly used for deleting standard Salesforce objects, but it does not cover all of the scenarios that users require.
There are several ways to mass delete records in Salesforce, but one of the most popular is with Skyvia.
In this article, we will take a glance at three different methods for mass deleting leads on Salesforce.
1. How to mass Delete Salesforce Records Using SQL
To begin, you must first create a query. And we’d use Skyvia.com to do so. To begin, we create a free Skyvia account.
Such registration does not necessitate the use of a credit card. Second, we create a query after registering by selecting SQL in the Query column and clicking +NEW in the top menu.
The query editor is launched. To query data, create a Salesforce connection by clicking the +New connection link (if you haven’t already) or selecting an existing Salesforce connection from the drop-down list on the left.
After you’ve selected the Salesforce connection, type the DELETE statement directly into the code editor. In the SQL WHERE clause, you can use advanced SQL features to determine criteria for deleting records.
You can put together multiple conditions with logical operators, use SQLite SQL functions, and even use IN clauses with subqueries.
If you don’t want to write the WHERE clause by hand, you can use the query builder to configure filters for the corresponding SELECT statement.
You can rerun this SELECT statement if necessary to ensure that it returns the records you require. Then, with minor changes, copy this WHERE clause to your DELETE statement.
For example, to delete all Salesforce leads created after October 3, 2020. We type in the following sentence: DELETE FROM Lead WHERE CreatedDate >’2020-10-03 00:00:00′ After entering the statement, we press the Execute button to put it into action.
The query result field displays the records that need to be deleted. Before deleting them, you can double-check the displayed records and then click the Apply All button. That way, you won’t have to worry about removing bad leads.
If you intend to reuse this DELETE statement in the future, save and name the query by clicking the Save button. If necessary, you can also include a description in your query.
2. How to mass delete Salesforce Records by CSV Using Data Loader
Mass deleting Salesforce records using CSV files is probably the most frequently requested method among thousands of Internet users.
This method is advantageous if you have hundreds (if not thousands) of records in a CSV file that must be removed as soon as possible. In our example, we delete accounts from Salesforce in bulk.
Following our example, you can mass delete Salesforce tasks, leads, reports, or any other data, in the same manner, using any data loader of your choice.
You will need to create an import package for this.
• To create an import package,
• Go to the top menu and select +NEW.
• In the Integration column, click Import.
When we open the package editor, the source type CSV upload manually is selected by default, which is what we need. Then, as a target, select the Salesforce connection from the drop-down list. If you haven’t already done so, click +New connection at the bottom of the drop-down list.
Once both connections are selected, add a task to the import package. To do this, go to the right and click the Add new link.
In the Task Editor that has been opened, click Browse and upload your CSV, check that CSV Separator is correctly selected, and browse through the CSV file columns. When everything is in place, proceed to the next step to modify the target settings.
Select the Account object from the Target drop-down list. Then, for our example, select the operation type for the task (Delete operation) and continue.
It would be best to map the source columns to the target columns in the task editor’s final step. Select ID from the drop-down list to map the source column to the target column if you have account IDs.
Target Lookup can be used when you don’t have account IDs or when they are unknown. The Lookup mapping enables them to be retrieved directly from target tables using other fields, such as identifying rows, such as names, for example. The target lookup is appropriate if your CSV file contains the Name field.
In our example, we also use the Target Lookup mapping. To set up such a lookup, go through the following steps:
1. Select a target object from the Lookup Object drop-down list to get the value (in our example, we select Name).
2. Select a column from the Lookup Object in the Result Column drop-down list to get the result value assigned to the mapped target column (in our example, we select Id; as a result, column).
3. Select the target lookup key column from the drop-down list. Two new drop-down menus appear. The first determines how the lookup object rows are selected. By default, it is set to a column.
4. Finally, in the bottom-most drop-down list, choose the source column, whose value must be equal to the lookup key column value.
Click Save to finish adding a task.
You will see an added task in the package editor with the accounts you want to delete based on the CSV list.
• To create an import package, click Create.
• Finally, click Run to delete the account.
3. How to mass Delete Salesforce Records by Filters Using Data Loader
If the records to be deleted can be obtained directly from Salesforce, Skyvia provides an alternative and much simpler method of mass deletion.
Create an import package, use the same Salesforce connection as source and target in the package editor, then delete data from the same Salesforce entity., apply a condition that will cause your data to be deleted, and run the package.
That’s all there is to it, and no CSV files are required.
When the package editor is launched;
• Under Source Type, select Data Source database or cloud app.
• Then, as a source, select the Salesforce connection.
• Next, choose the Salesforce connection as a target. If both connections are chosen,
• Continue by adding a task to the import package.
• When you click the Add new link, you are taken to the Task Editor window.
Select Contact from the Source drop-down list on the Task Editor window’s Source Definition tab.
In the Filter section, enter;
• On the right, click the +Condition button and specify the condition under which records will be deleted.
• We choose the Contact object from the first drop-down list.
• In the second drop-down menu, we choose CreatedDate.
• We select “the greater than sign >” in the third drop-down list because we want to delete contacts after a specific date.
• Using the opened calendar box, we select an appropriate date from the fourth drop-down list. Then we try to delete contacts created after 10.08.2020 00:00:00 in our example.
• When everything on this tab is ready, click Next step to adjust target settings.
Choosing a target from the drop-down menu;
• Choose the Contact object.
• Next, choose the operation type for the task (Delete operation for our case).
• To continue with mapping, click Next step.
• The Required target columns must be mapped for the task to be valid.
• When you’re finished adding tasks, then click Save.
In the package editor, locate an added task with contacts you want to delete based on your specified condition.
• To create an import package, click Create.
• Finally, click Run to proceed with the deletion.
In the same way, you would create an import package to mass delete opportunities in Salesforce or any other object.
In this article, we attempted to describe three methods for mass deleting Salesforce records/leads.
You can choose the method that you believe is best for your company’s needs.
General way to mass delete Salesforce data
Follow the steps below to do this in a friendly and general manner.
To mass delete data, the User must first modify all data permissions.
The following are the summary and quick steps for mass deleting Accounts, Contacts, Leads, and so on:
• In Setup, type Mass Delete Records into the Quick Find box, select Mass Delete Records and click the link for the record type to delete.
• Examine the data that will be deleted along with the records.
• Specify the conditions that the selected items must meet, such as “State equals California.”
• When deleting accounts, specify whether you want to delete accounts that have attached closed/won opportunities or accounts that have attached opportunities owned by other users.
• When deleting products, select Archive Products if you also want to delete products on opportunities.
• Select this option to:
• Remove products that are no longer relevant to opportunities and place them in the Recycle Bin.
• Keep track of products that are on the market. These items are not disposed of in the Recycle Bin and cannot be recovered.
• Uncheck this box to delete only products that are not on opportunities. Selected products on opportunities will remain checked after deletion to indicate that they were not deleted.
• Select Search to find records that match your criteria and then select the items you want to delete. Check the box in the column header to select all of the items that are currently displayed.
• Select Permanently delete the selected records to delete the records permanently.
• Selecting this option stops you from recovering the records you’ve chosen from the Recycle Bin.
• Select Delete.
• If you opt not to permanently delete the specified data, deleted items are relocated to the Recycle Bin.