Activity Forums Salesforce® Discussions Delete more than 10000 records using script without limit in Salesforce Apex

  • S

    Member
    June 7, 2017 at 12:09 pm

    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.

  • Ankit Gupta

    Member
    June 7, 2017 at 1:22 pm

    Hi Pavan,

    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.

  • Shaik

    Member
    June 9, 2017 at 6:15 pm

    Write a batch class to delete the records.

    Two ways of Executing the batch class :

    1. Execute it in "Anonymous" block or
    2. 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)
  • Ted

    Member
    July 17, 2017 at 2:27 am

    Hi Pavan:

    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.

    https://www.essa-software.com/

    You can use the promotion code ESSA2017 on the register page to get the free, full version.

    I hope this helps!

  • Parul

    Member
    September 29, 2018 at 1:17 am

    Use batch class

  • shariq

    Member
    September 29, 2018 at 10:34 am

    Write a batch class to delete the records.

  • Avnish Yadav

    Member
    September 30, 2018 at 1:38 am

    Hello,

    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);

    Thanks.

Log In to reply.

Popular Salesforce Blogs