function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rezasadoddin1.3878325535858708E12rezasadoddin1.3878325535858708E12 

Deleting all the records of a custom object

How can I delete all the records of a custom object in Developer Edition?
Cory CowgillCory Cowgill
If this is Developer Edition, and you have less than 10,000 rows of data, the easiest way may be to just do the following:

Go to the Developer Console in the upper right of your web brower. Click Debug -> Execute Anonymous Apex.

Delete SOQL

Enter in a SOQL to select all the records from the object. Then click Excecute. You'll get a success like the below:

delete

Now all your records have been deleted.
Rahul_sgRahul_sg
Go to developer console >Debug > open Execute anonymous window

Write the following code:

List<Sobject__C> SobjLst = [select id from Sobject__C];
delete SobjLst;

click on the execute button.
note: Replace the Sobject__C with actual custom object api name

rezasadoddin1.3878325535858708E12rezasadoddin1.3878325535858708E12
Thansk for your clear and detailed answers.
Sridhar BonagiriSridhar Bonagiri
Hi,

I think you can use 'Truncate' option to delete all records in a custom object.

for more reference please go through the below URL.

https://help.salesforce.com/HTViewHelpDoc?id=dev_object_trunc_overview.htm&language=en_US

Regards,
Sridhar Bonagiri
Cory CowgillCory Cowgill
Truncate has serious limitations. It won't work with objects that have relationships (lookup fields) a and other nuances. I have found using SOQL deletes more effective with small batches of deletes.
sfdcvirajsfdcviraj

I had to delete all the data or case numbers of a custom object. What I simply did is used the below query to fire and delete all the data in one go.
Open developer console/Debug/Open Execute Anonymous window/

delete [select Name from LogCase__c];

This can be extremely dangerous so use it very carefully. Also do it only when you know the exact impact of doing it.
After deleting the records, I did not find the data in the Recycle Bin. So be carefull.

marvin diligencia 16marvin diligencia 16
Thank you this is really helpful ! :)
Sarathy JPSarathy JP
Thanks it works Fantastic!
Gopala Karthigai Selvan MurugesanGopala Karthigai Selvan Murugesan
What if we have more than 10000 records in that custom object???
David @ ConfigeroDavid @ Configero
If you have less than 10,000 records you can run delete [SELECT Id FROM SObject LIMIT 10000] as anonymous apex code through the developer console or other IDE of your choice that utilizes Salesforce's APIs.

If you have more than 10,000 records and it is reasonable, just run a delete [SELECT Id FROM SObject LIMIT 10000] a few times, assuming this is a one off scenario you won't be repeating frequently or scheduled.  if this is a repeated/scheduled action, you might want to look into a batch and/or scheduled job, or using the bulk API which would be excellent for this as well https://developer.salesforce.com/page/Bulk_API
Bhanu joshi 10Bhanu joshi 10
We can export data using data loader and then delete them on the bases of Id's ,if we have more than 10K records
sri.nathsri.nath
With the data storage limitations in Developer org, chances are less than the object will have more than 20K records. Which means, running the code snippet provided by @Cory Cowgill twice will do the job.
If you are so particular about the best practice, you can do this in two ways:
1. Use data loader/workbench to export the ids of the records and use the delete operation of DL/workbench to delete them.
2. Create a batch apex, which queries all records in the start method. In executing method add them to list and delete the records. Run the batch suing dev console.This ensures that you don't run into any governor limits.
Suraj Tripathi 47Suraj Tripathi 47
Hi rezasadoddin1.3878325535858708E12,
You can try this one,
//Sobject__C is your custom object, you can replace.

List<Sobject__C> listOfCustomObject = [Select id from Sobject__C];
    delete listOfCustomObject;

Pls, Mark it as the Best answer If You find it helpful !!
Thanks
Sanket VidhateSanket Vidhate
Try this
delete [Select Id from CustomObject__c];