15

Is there a DML or other way to delete all records from the developer console? For example, we have 100K Leads in our testing environment and we would like to delete all of them in one operation.

Is that possible?

By the way, I saw there is a mass delete option, although it only lets you delete a few hundreds records at a time.... (using Setup-> Administration Setup->Data Management -> Mass Delete Records.)

18

You can delete records from the developer console with the line

delete [SELECT Id FROM MyObject];

However, this isn't going to delete 100k records successfully due to governor limits. You're going to need to use dataloader to export the 100k records, then use the export to delete the records.

Edit: Better than that, you can use LIMIT to select a subset, and then rerun the command after each execution

delete [SELECT Id FROM MyObject LIMIT 10000];
| improve this answer | |
  • 7
    Is this answer still valid? When I try it I got error "Invalid query: The query has to start with 'FIND' or 'SELECT'" – Zorji Oct 10 '16 at 0:18
  • This answer is still valid, at least for standard objects like 'Contact'. I was able to delete records with a vengeance. (This is far superior to the troublesome 'mass delete' interface that deletes 250 at a time, assuming there no hidden errors that don't allow records to be deleted..! – ryanm Feb 7 '17 at 23:48
  • I am not able to use delete for deleting Contacts in developer console. I tried the SOQL and it did not work. Got the error mentioned by @Zorji – stack_pointer is EXTINCT Apr 25 '17 at 3:42
6

One way to delete using Developer Console is to first execute your query

SELECT Id from My_Custom_Object__c

Then highlight all the result rows and click on the Delete Row button at the bottom.

enter image description here

| improve this answer | |
  • @ Bhavana thanks, simple and efficient (ok) – Vishal Kumar C V Jun 24 at 8:00
  • The question asks how to delete 100k records. This doesn't seem efficient for that. – Shonin Aug 11 at 22:19
4

Using Apex Data Loader to delete records:

First, you have to export all the records (the ID will be sufficient) to a csv file. Then you can delete all the records based on that csv file. When you perform the delete make sure you map the ID column of the csv file to the Id column of the object.

This way took me a few minutes to delete 120K records (Lead).

| improve this answer | |
1

I add something to your answers. There are two ways to solve this problem, in addition to the console. I think that the console could be very useful, but maybe in production one wants to have an higher "control" on the data. In that case there are two ways.

1) Use the Workbench:

  • connect to the product (if you have a developer licence check this option) or to the test org;
  • Tab Query - click on SOQL query;
  • write a query to identify the records to delete: SELECT Id FROM Account WHERE revenue > 1234 ;
  • check the Bulk CSV radio button;
  • click on the "Query" button, wait the processing of the records, and then download it (it will be saved in .csv format);

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!

1) Use the Data Loader:

  • download it from

Setup - Data Management - Data Loader

  • enter in the Data Loader using the password of your org + the security token;
  • check in the Settings tab if you are accessing in the right environment (test.salesforce or login.salesforce);
  • following the instructions suggested in the previous answer.
| improve this answer | |
1

To delete more than 50,000 records, you can use the DataLoader program. Follow these steps...

-Open the data loader and choose "export". Navigate to your object and select it, then choose the 'id' field. You only need the 'id' for each record in order to delete it. Export this to a csv file.

-Open the data loader again and choose "delete". Navigate to your object and select it. Then import the csv file you have just saved containing the IDs for all your records. Import that and map the 'id' field to that of your object.

| improve this answer | |
0

2 ways,

  • Either batch apex with acceptable batch size and business logic.
  • Apex Data Loader (as explained in above answers)
    • Using bulk api you can really speed up the deletion.
    • Normal apex loader deletion can also do the trick with specified batch size.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.