Good day everyone I have a problem in regards with deletion. This is my scenario. I have a custom object let say as AccountParent__c
. I also created a lookup field in my Account
object which is related to my AccountParent__c
object. One AccountParent__c
record has many Accounts
.And what I want is that when I delete a AccountParent__c
record, all account related to it will also be deleted.What is the best thing I have to do ? At the moment I've created a batch process for deleting the account and when there is a deletion for AccountParent__c
record, a trigger will call the batch process for account deletion. But it seems it is not working. I guess the reason is that the AccountParent__c
is already deleted but the batch process is still running.(I use batch because in my case there are possibilities that my related records are more than 10000)Do you have any idea how to solve my problem ? Below is a sample code for my trigger.
trigger deletionAcc on AccountParent__c (before delete) {
for (AccountParent__c theold : Trigger.old) {
// below is the batch use to delete all related list
delBatch b = new delBatch(String.valueOf(theold.Id));
database.executebatch(b);
}
}
please help.Thank you...