- June 7, 2017 at 10:52 am #20367Pavan #632
Delete more than 10000 records using script without limit in Salesforce Apex
How to delete more than 10000 records using script without limit in Salesforce Apex?June 7, 2017 at 12:09 pm #20370S #628
Better to use Data Loader for such scenario.
Even if you have to Delete it using Apex script with some custom logic, I would recommend you to add records to collection and break it at 9990 and then create another instance of collection to update. You can write automated logic to break the collection based on the size and perform DML on them.June 7, 2017 at 1:22 pm #20373Ankit Gupta #616
If you are using vf page to delete the records. You can use asynchronous call to call apex method and perform the delete in each transaction.
Also you can call action function recursively on the basis of certain condition from oncomplete of action method.June 9, 2017 at 6:15 pm #20414Shaik #601
Write a batch class to delete the records.
Two ways of Executing the batch class :
July 17, 2017 at 2:27 am #20976Ted #644
- Execute it in “Anonymous” block or
- Create a VF page with a Delete button which invokes the batch class(with VF page you can catch the errors while performing delete operation and can show it on VF page as error messages)
So there is no easy way to do mass deletes in Salesforce due to the limits in place. I’ve been able to use ESSA’s bulk delete feature, which is super easy.
You can use the promotion code ESSA2017 on the register page to get the free, full version.
I hope this helps!September 29, 2018 at 1:17 am #39925September 29, 2018 at 10:34 am #40913September 30, 2018 at 1:38 am #41340Avnish Yadav #3
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);
Please Register to reply to this topic. /