+ Start a Discussion

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


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)
   sforce.apex.execute("ObjectHandler","deleteAllObjects", {id:"{!Account.Id}"});
   window.alert("Objects deleted." );

 I hope that helps!