In a master-detail relationship, if I am deleting the parent record,lets assume half of its child records were deleted after which I was getting some exception and the remaining child records were not deleted. So in this case, whether the child records which were deleted will it be rolled-back?
-
Deleting the master will delete all of it's children automatically by the platform. What do you mean half deletion?– Xi XiaoNov 14, 2018 at 8:54
-
Like if half of the child records were deleted and then if any exception occurs, what will happen to those deleted records?– SindhujaNov 14, 2018 at 9:09
2 Answers
It depends how you are performing the delete operation.
If you are deleting records with
delete <list of child records>
and if any errors occurs then no records will get deleted. Basically, it is treated as all or noneIf you are deleting with
Database.delete(<list of child records>, false)
wherefalse
allows partial deletion then those records will not get rollback which are not throwing as errors.If you are deleting with
Database.delete(<list of child records>, true)
and if any error occurs then all will be rolled back.
Presuming that you're using the cascade deletion feature, all records will be deleted without validation or triggers. The only way it can fail is a master record has about 50,000 children, and this will be an automatic roll back. In a more general sense, Salesforce automatically rolls back a transaction if any record therein fails to insert/update/delete/undelete. Obviously, in cases of developers writing code, they can override this behavior, but the default behavior is to automatically roll back in the case of an exception.