6

I'm trying to undelete records using apex and it is throwing me an error: entity is deleted

List<MyObject__c> undeleteObj = [select id, Unique_Id__c from MyObject__c 
            where Unique_Id__c IN :uniqueIds];
undelete undeleteObj;

This code is in the trigger on after update. Schema is same, record does exists in org and I verified it in Real Force. I can't do this using data loader since it is part of workflow process where the record is undeleted if it was previously deleted else or a new record is added. Any suggestions/workarounds will be appreciated.

1
  • have you tried the above code with the ALL ROWS keyword in the query to bring back the deleted records? Mar 24, 2016 at 16:19

1 Answer 1

9

Not entirely sure but I think you would need to add ALL ROWS in your select statement otherwise it won't retrieve the deleted records

1
  • 4
    Also, WHERE Unique_Id__c IN :uniqueIds AND IsDeleted = TRUE, or you'd get an "Entity is not in the recycle bin" error.
    – sfdcfox
    Mar 24, 2016 at 17:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .