Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

This question might be more towards the approach than the technical side. The scenario is the following:

I have to run a scheduler to delete some records. The record size is always going to be less than 10K!

Can I retrieve all the results in a list like:

List <sObject> listsObject = [Select Id from sObject where Test__c = true Limit 9000];
Delete listsObject;

Will this be able to delete all the records in the list?! OR Will this only delete the 200 records? Please let me know.

Also, I know I could follow the batch Apex Approach but I want to know first if this will work, and if this certainly works I dont have to write Batch Apex and then schedule it.

Cheers.

share|improve this question

1 Answer 1

up vote 7 down vote accepted

Yes, it will work just fine. You can even write it in 1 line:

delete [Select Id from sObject where Test__c = true Limit 9000];

It will fail the whole delete operation though if there's any kind of problem (like "before delete" trigger that makes some extra checks and complains). You can set it to "delete what you can, I'll deal with errors separately" by using another version of delete that takes an extra parameter.

Database.delete([Select Id from sObject where Test__c = true Limit 9000], false);
share|improve this answer
    
Thanks @eyescream for the help! Much appreciated. –  subodhbahl Jan 14 '13 at 15:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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