function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
lakshmi25lakshmi25 

how to perform the mass deletion using BatchApex

i created one custom button DeleteAll in account object listview how to  perform the mass delition of the  records using BatchApex .please send the sample code

SLockardSLockard

Here is a sample that will delete all of the 'cutom object' for an account.

The class:

Global class ObjectHandler
{
    WebService static void deleteAllObjects(String id)
    {
        List<CustomObject__c> objsToDelete = [SELECT Id FROM CustomObject__c WHERE Account__c = :id];
        delete objsToDelete;
    }
}

 And the on click javascript button :

var result=confirm("Are you sure you want to delete all of these objects?");
if (result==true)
{
   {!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
   {!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
   sforce.apex.execute("ObjectHandler","deleteAllObjects", {id:"{!Account.Id}"});
   window.alert("Objects deleted." );
}

 I hope that helps!