Using SOQL, how do I truncate an object or delete all rows. For example

DELETE (Select id FROM MyObject__c)


delete [select Id FROM MyObject__c]



All 3 example commands in the Developer console returns:

The query has to start with 'FIND' or 'SELECT'

You can't perform any DML using SOQL. The 'Q' stands for 'Query'.

If you want to use Execute Anonymous, then you can use:

delete [select id from myobject__c limit 10000];

However, this has a 10,000 row limit, so that might not be appropriate in all cases.

Salesforce can query 50,000 records at a time but due to governor limit it'll allow only 10,000 DML operation

The only way to perform a quick truncate would be to use the UI to initiate the truncate.

| improve this answer | |
  • Thanks - That's a horrible limitation. But it is what it is. – PhillyNJ Mar 2 '15 at 20:41
  • So there is no way to test this via Console and I eventually need to do this via SOAP, it looks like the best option is to use a Select() then Delete() salesforce.com/developer/docs/api/Content/… – PhillyNJ Mar 2 '15 at 20:55

You can truncate a custom object.

For the Truncate option to show on custom object, do not forget to check ‘Enable Custom Object Truncate’ from Setup -> Customize -> User Interface as shown below

Or from an anonymous window, if your row count is less than or equal 10000, just run the code

DELETE[SELECT id FROM myCustomObject__c LIMIT 10000];
| 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.