At least once, we have come across the situation when we needed to quickly mass delete data from Salesforce, for example, accounts, contacts, leads or any other standard/custom objects that were previously imported incorrectly or those objects, which we simply want to delete out of Salesforce forever. For example, we have made a bulk upload of leads into Salesforce but would like to return everything back – in this article we describe how to do it with ease.
It is worth mentioning that Salesforce has its own tool for mass data deleting. Mostly, this built-in tool is used for deleting standard Salesforce objects, however, it does not cover all the scenarios required by users.
Unlike Apex Data Loader, Skyvia is a cloud-based solution, which needs minimal configuration and only a web browser to be accessed from anywhere. With Skyvia, you can bulk delete any data or any custom or standard object from Salesforce, using either Query or Skyvia Data Loader.
Prior to mass deleting any Salesforce records, you can play it safe and back up data using Skyvia Backup Product. Backed up data can be viewed and later exported or restored directly to Salesforce via web browser from the Skyvia interface. We offer up to 1 GB of storage for free to our clients. Below we describe 3 ways how you can easily bulk delete data from Salesforce. Your deep technical knowledge is not required.
Table of contents
- Mass Delete Salesforce Records Using SQL
- Mass Delete Salesforce Records by CSV Using Data Loader
- Mass Delete Salesforce Records by Filters Using Data Loader
1. Mass Delete Salesforce Records Using SQL
Skyvia Query is an online SQL client and query builder tool that allows querying and managing cloud and relational data with SQL statements. It is a perfect solution for users who are familiar with SQL as you simply enter SQL statements via code editor and execute the query. If you are not so good at SQL, you can try to use our visual query builder. To read more about it, visit our Skyvia documentation.
Except for DELETE statements, Skyvia Query also supports SQL SELECT, INSERT and UPDATE for cloud sources. For relational databases, Skyvia can execute all the statements supported by the database, including DDL statements.
Let us get started with creating a query. First, we register a free Skyvia account. Such registration requires no credit card. Second, after registering, we create a query simply by clicking +NEW in the top menu and selecting SQL in the Query column.
The query editor opens. To query data, first you need to create a connection to Salesforce by clicking the +New connection link (in case you have not created it yet) or select the already created Salesforce connection from the drop-down list on the left.
After the Salesforce connection is selected, enter the DELETE statement directly into the code editor. You can use advanced SQL features to determine criteria for records to delete in the SQL WHERE clause. You can add multiple conditions, unite them with logical operators, use SQLite SQL functions, even use IN clauses with subqueries.
If you don’t want to compose the WHERE clause manually, you can use visual query builder to configure filters for the corresponding SELECT statement visually. If necessary, you may run this SELECT statement to be sure that it returns the records you need. Then you can copy this WHERE clause to your DELETE statement with slight modifications.
In our example, we bulk delete leads from Salesforce created after November 3, 2020. We enter the following statement: DELETE FROM Lead WHERE CreatedDate > ‘2020-11-03 00:00:00’. After we’ve entered the statement, we click the Execute button to run it.
The query result field displays records to be deleted. Before deleting them, you can check whether the displayed records are correct and only after that click the Apply All button. That helps not to worry about removing wrong leads.
If you plan to reuse this DELETE statement in the future, click the Save button to save and name the query. You can also add a description to your query if necessary.
The same way you can mass delete custom object records from Salesforce. As mentioned above, Skyvia supports deleting both standard and custom objects. For this, you need to know a bit of SQL or use our visual query builder to add a necessary condition.
What is also convenient is that Skyvia offers 5 free queries per day according to the free query pricing plan. Such a number of queries can be enough if you need to mass delete records occasionally.
2. Mass Delete Salesforce Records by CSV Using Data Loader
Mass deleting Salesforce records via CSV files is probably the most frequently requested method among thousands of users on the Internet. This method is really useful if you have hundreds (if not thousands) of records in a CSV file, which need to be removed in the fastest possible way. Below we show how to do it with Skyvia Data Loader via import operation. In our example, we mass delete accounts from Salesforce. Following our example, you can mass delete tasks from Salesforce, mass delete leads, reports or any other data in exactly the same way.
For this, you need to create an import package. To create an import package, click +NEW in the top menu and select Import in the Integration column.
When the package editor opens, the source type CSV upload manually is selected by default, which is what we actually need. Next, you should select the Salesforce connection from the drop-down list as a target. If you haven’t created the Salesforce connection yet, click +New connection at the bottom of the drop-down list. You can read more on how to create a connection in our Salesforce import tutorial.
When both connections are selected, proceed with adding a task to the import package. For this, click the Add new link on the right.
In the opened Task Editor, click browse and upload your CSV, check whether CSV Separator is selected correctly and look through the columns of the CSV file. When everything is okay, click Next step to adjust target settings.
In the Target drop-down list, select the Account object. Then, select the operation type for the task (Delete operation for our case) and proceed further.
On the last step of the task editor, you should map the source columns to the target columns. If you have account IDs, you simply map source column to target column by selecting ID in the drop-down list.
When you do not have account IDs or they are unknown, you can use Target Lookup. The Lookup mapping allows getting them directly from target tables by other fields, identifying rows, such as names, for example. If you have the Name field in your CSV file, the target lookup is right for you.
So, in our example, we use the Target Lookup mapping too. To configure such a lookup, perform the following steps:
- In the Lookup Object drop-down list, select a target object to get the value from (in our example, we select Name).
- In the Result Column drop-down list, select a column from the Lookup Object to get the result value that will be assigned to the mapped target column (in our example, we select Id as a result column).
- In the drop-down list, select the target lookup key column. Two new drop-down lists are displayed. The first one determines how to select the lookup object rows. It is set to Column by default.
- Finally, in the bottom most drop-down list, select the source column, the value of which must be equal to the lookup key column value (in our example, it is Name).
To finish adding a task, click Save.
In the package editor, you will see an added task with accounts you want to delete according to the CSV list. Click Create to create an import package and then click Run to execute account deletion.
3. Mass Delete Salesforce Records by Filters Using Data Loader
If the records for deleting can be received from Salesforce itself, Skyvia offers an alternative and much simpler way to mass delete them. You just need to create an import package, select the same Salesforce connection as source and target in the package editor, select the same Salesforce object to delete data from, apply a certain condition according to which your data will be deleted and run the package. It is as simple as that and no CSV files are required.
Let us mass delete contacts from Salesforce as an example. You create an import package the same way as described above. When the package editor opens, click Data Source database or cloud app under Source Type and select the Salesforce connection as a source. Then, select the Salesforce connection as a target. When both connections are selected, proceed with adding a task to the import package. After clicking the Add new link, you are dropped into the Task Editor window.
On the Source Definition tab of the Task Editor window, select Contact in the Source drop-down list.
In the Filter section, click the +Condition button on the right and set the condition according to which records will be deleted. In the first drop-down list, we select Contact object. In the second drop-down list, we select CreatedDate. In the third drop-down list, we select “the greater than sign >” as we want to delete contacts after a certain date. In the fourth drop-down list, we choose an appropriate date using the opened calendar box. In our example, we delete contacts created after 10.08.2020 00:00:00.
Skyvia does not limit you to a single condition only. You can mass delete data by adding any other condition which better meets your personal or business needs. In Skyvia, you can also add multiple filters, which can be united in groups. Each group may consist of several filters and/or subgroups united with a logical operator (AND or OR). You can read more about filtering options in the Filter Settings topic.
When everything is ready on this tab, click Next step to adjust target settings.
From the Target drop-down list, select the Contact object. Then, select the operation type for the task (Delete operation for our case).
Click Next step to proceed with mapping. Target columns, which are marked as Required, must be mapped in order for the task to be valid. In our case, it is the ID column, and it has already been mapped automatically by Skyvia. To finish adding a task, click Save.
n the package editor, you will see an added task with contacts you want to delete according to the set condition. Click Create to create an import package and then click Run to execute deletion.
The same way you create an import package to mass delete opportunities in Salesforce, for example, or any other object you want.
Register right now and get 5% off for any Skyvia subscription using this coupon code: SkyviaBlog_2022_5off
In this article, we’ve tried our best to describe in detail three ways how you can mass delete Salesforce records. You can decide on your own, which way you find the most suitable for your business needs. We hope this article was helpful for you. What other data integration operations may be useful for you to read in our blog? Leave your comment or feedback – we will appreciate it!