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
ketan vinodrai mehtaketan vinodrai mehta 

Deleting loopup objects in bulk.

Hi,
    We have multiple lookup related child objects for an Account object. We need to delete the child records based on some criteria before deleting the parent object. For less than 50K child records, it is working fine. How to delete child records in lakhs? Exmple will help a lot.

Thanks,
 
Srinivas SSrinivas S
Hi ketan,

Create a batch class, in start method create a dynamic query which will pass the result to execute method then upto 50 million records will be processed.
Note: Use Database.queryLocator as reuturn type.

Thanks,
Srinivas
- Please mark as solution if your problem is resolved.
Srinivas SSrinivas S
Note: From a trigger you invoke the batch class if you are writing a before delete trigger, please invoke the batch class by supply all the contact ids.

Thanks,
Srinivas
- Please mark as solution if your problem is resolved.
ketan vinodrai mehtaketan vinodrai mehta
Hi Srinivasa,
     I want to run the job as scheduled, say I have 700000 Accounts and have child objects as Contact (500000 records) and Job__c (600000 records), I want to delete child records as well as parent with some conditions. Can u give me an example plz.