title: Salesforce - Best way to delete multiple records from an Object hierarchy and error handling in Salesforce
body: <p><strong>Context:</strong> 
  We would like to delete multiple records in the Case and its related/child objects. The child objects have few related objects. There are 4 to 5 levels of hierarchy as follows</p>
  
  <ul>
  <li>Case</li>
  <li>--Task</li>
  <li>-----Child1</li>
  <li>--------Child2</li>
  <li><p>-----------Child3</p>
  
  <p> 
  The related objects are having master-child relationship with cascade delete set to false.</p></li>
  </ul>
  
  <p>Currently the way we are deleting cases in a batch is as follows</p>
  
  <ol>
  <li>Collect all cases in the batch</li>
  <li>Collect all the tasks for all cases in the batch</li>
  <li>Collect all the Child1 records for all Cases in the batch</li>
  <li>Collect all the Child2 records for all Cases in the batch</li>
  <li>Collect all the Child3 records for all Cases in the batch</li>
  </ol>
  
  <p>Then delete each set of records in batch using bulk delete. The advantage is we will have only 5 deletes per batch and we don't hit governor limits.</p>
  
  <p>However the down side of this process is, when there is error in deleting in any of the steps above, whole transaction is rolled back.  Though we can get which delete caused he error, we cannot role back objects related to only that particular case.</p>
  
  <p><strong>Question:</strong></p>
  
  <ol>
  <li>Is there are any better way to handle deleting of records and child
  records.  </li>
  <li>Is there a way to rollback only the cases and the child
  records which had error</li>
  </ol>