You need to sign in to do that
Don't have an account?

Mass Delete
I'm trying to write a class that will delete all records in a custom object with a specific status. Can't seem to get pass the syntax.
I've got this...
public with sharing class DeletePostedToHistory{
List<CustomObj__c> CustomObj = [
select status__c
from CustomObj__c
where status__c = 'Posted to History'];
delete CustomObj;
}
But I get the error "expecting right curly bracket, found 'delete'
What am I missing here?
Thanks,
I am going to take a stab at this but I am still continously learning myself.
It looks like you are trying to execute SOQL from with the class itself. Would you need something like this?
All Answers
I am going to take a stab at this but I am still continously learning myself.
It looks like you are trying to execute SOQL from with the class itself. Would you need something like this?
A few things:
1. In Apex Trigger or Visualforce PAge, you can oly retrieve 50000 records in SOQL calls, AND you can only perform a DML operation on 10000 records.
2. If you need to process more than that, I'd suggest either using Apex Data Loader OR you can write an Apex Batch Job to preform a mass operation over all records in the system.
Other than that, this below should work. Note you need to select the ID, because that is what a delete operation is going to run off of.
public void DeleteIt()
{
List<CustomObj__c> deleteObjs = [select id, status__c from CustomObj__c where Status__c = 'Posted to History' limit 10000];
delete deleteObjs;
}
Actually you can add a loop. For example if you have 10000 records to delete, you could say:
Integer i = 0; i <= 10; i++
Then you can delete 10000 records.
Hi Jeff,
You are getting this error because you have pasted your code directly to your class.
I would suggest you to write your code in a method and than call the method from somewhere.
If I am able to answer your query , please mark it as a solution.
Cheers !
Niket
Certified Administrator | Certified Developer
MyBlog
Thanks so much everyone!