function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KerryGroup DevKerryGroup Dev 

how do I undelete a record?

I have an opportunity that I would like to undelete. I can find the data in the database using both Apex Explorer and through an APEX query if I use the ALL ROWS flag. I understand how to undelete using the apex command Undelete:

 

id OppId = '0068000000VVkwlAAD';
Opportunity opp = [select id, name from opportunity where id =: OppId ALL ROWS];

Database.UndeleteResult result = Database.Undelete(opp, false);
System.debug(result);

 

But... this record is not in the recycle bin. I get an error:

 |USER_DEBUG|[5,1]|DEBUG|Database.UndeleteResult[getErrors=(Database.Error[getFields=();getMessage=Entity is not in the recycle bin;getStatusCode=System.StatusCode.UNDELETE_FAILED;]);getId=0068000000VVkwlAAD;isSuccess=false;]

 

So the data is in the system... I just want to flip the isdeleted flag... Can I do this?

imuino2imuino2

According to the documentation the value of isdeleted is not writable or editable.

Are you sure that the isdeleted is on true? because if it is it should be on the recycle bin.

 

Ignacio

KerryGroup DevKerryGroup Dev

Thanks for the reply. I am sure that the IsDeleted flag is set. I ran this query:

 

select id, name, createddate, isdeleted, lastmodifiedbyid from Opportunity where id = '0068000000VVkwlAAD'

 

And I can see in the result that the IsDeleted flag is set. (I'm using Apex Explorer 8.0 and the Query All button)

 

The object is not in the recycle bin. I have looked (for the entire org) and I have also run the command undelete. When I run that command I get an error that says the record is not in the recycle bin. What is interesting is that I CAN query for the record to generate the sObject before I call the undelete command.

Salesforce NewbieSalesforce Newbie

 

I  am also encountering this error when I try to undelete an account that was cleared out of the Recycle Bin (UNDELETE_FAILED, Entity is not in the recycle bin: []). 

I am getting this error when I Execute Anonymous the following in Force.com IDE :

 

Database.undelete(Account ID);

 

The only difference with my account and the previous post from KerryGroup Dev is that the ISDELETED is set to TRUE in Account object.  Is there another DML command I should be using?  I did try to upsert this account instead through Dataloader but I get an error message saying 'entity is deleted'

ImpactMGImpactMG

I encounter the same error. Object IsDeleted=true, but can't be undeleted, because "it's not in the recycle bin". Any explaination to that?