Retrieving deleted Entity Objects

I have seen a couple of use cases where developers need to iterate through the deleted Entity Objects and perform validations based on various conditions. Steve shared some pointers, which helped me to find a solution. The following code snippet may help you to identify the deleted entities.

public class EmployeesImpl extends EntityImpl {
 public ArrayList<EntityImpl> findDeletedEmployees() {
    ArrayList<EntityImpl> deletedList = 
                              new ArrayList<EntityImpl>();
    Iterator iterator =
   while (iterator.hasNext()) {
      EmployeesImpl emp = (EmployeesImpl);
       if (emp.getEntityState() 
                       == Entity.STATUS_DELETED) {
          // Keep soft ref. if worried on GC              
    return deletedList;
    // Rest of  your code goes here