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
sdusdu 

Problems deleting records when there are large number of child records

If I have a master and a child object and there are lots of records in the child object. It is impossible to delete these records in Apex code. The error is 'DELETE_OPERATION_TOO_LARGE, Cascade deleting too many records'.

 

Note that I am using an Apex batch to delete the records from the child object first, then delete the records in the parent object and the error occurs when I try to delete the records in the master object. According to salesforce support, the reason for the error is the child records are still in recycle bin, and when deleting the master records, they need to be moved to another table somehow. If this is the only obstacle, I can delete the records permenantly by using Database.emptyRecycleBin(). But the error still occurs even after I empty the recycle bin. Aparently the records are still somewhere and salesforce still need to do something with them. Only after salesforce support manually cleaned them out, I am able to delete the master records.

 

Salesforce support says this is working as designed. I just do not see this make sense. We are building an app, have lots of customers, and they may need to perform such deletion very often. We have to open ticket with salesforce everytime we hit the error?