Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
    
have you tried the above code with the ALL ROWS keyword in the query to bring back the deleted records? – Michael Fleming Mar 24 at 16:19
up vote 9 down vote accepted

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

share|improve this answer
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 at 17:02
    
thanks all, it works as expected :) – user569925 Mar 24 at 17:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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