0

I have 4 custom objects which has master-detail relationship with each other.

Obj A (Parent)

|

Obj B (Child of Obj A)

|

Obj C (Child of Obj B)

|

Obj D (Child of Obj C)

So if I delete Obj A , all the child records of these objects has to be deleted. But I face an issue when I try to delete an Obj A record which has large number of child records.The error is "Delete failed. First exception on row 0 with id "Id of the record"; first error: DELETE_OPERATION_TOO_LARGE, Cascade deleting too many records: occurring when cascading to Obj D records: []"

I tried to empty the recycle bin by calling Database.emptyRecycleBin(List ObjArecords) after deleting but still the above error occurs.

Is there any way to rectify this issue.? How will I delete all these records?

3

If you're running in to this issue, you'll have to delete the "D" records first and work your way back up to the top. This will require asynchronous code, because the limit is an absolute limit per transaction, and is far greater than you can delete directly (50,000 cascade deletes versus 10,000 direct deletes).

| improve this answer | |
  • So can I write a batch class and delete from Obj D records till Obj A. Will that still throw Cascade deletion error? – Sindhuja Nov 26 '18 at 9:45
  • 1
    @Sindhuja No, as long as you're deleting them in order, you will not violate the 50,000 row cascade limit. – sfdcfox Nov 26 '18 at 9:46
  • I created 3 batch classes each one for deleting B,C and D records.And finally in the last batch class , I am trying to delete the parent object A record. All the child records were deleted but still I am getting the same error "First error: Delete failed. First exception on row 0 with id Id of the parent record; first error: DELETE_OPERATION_TOO_LARGE, Cascade deleting too many records: occurring when cascading to Obj D records: []". This error is occurring while trying to delete parent record. – Sindhuja Nov 30 '18 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.