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
balaji_sfbalaji_sf 

Wanted to the retrieve the deleted records

Hi

 

Is there any way to retrieve the deleted record through API. 

 

I am getting the deleted records ID from the function getDeleted().

and tried to retrieve the record using SOQL , but i can't get it. 

 

Please let me if there is any other way.

 

Thanks

Balaji

Best Answer chosen by Admin (Salesforce Developers) 
apexsutherlandapexsutherland

balaji_sf are you using the "QueryAll()" API call when you try to retrieve the delete records? Using the regular "Query()" call won't allow you to retrieve delete records. See the API documentation on the "QueryAll()" API call here:

 

http://www.salesforce.com/us/developer/docs/api/index_Left.htm#StartTopic=Content/sforce_api_calls_queryall.htm 

All Answers

apexsutherlandapexsutherland

balaji_sf are you using the "QueryAll()" API call when you try to retrieve the delete records? Using the regular "Query()" call won't allow you to retrieve delete records. See the API documentation on the "QueryAll()" API call here:

 

http://www.salesforce.com/us/developer/docs/api/index_Left.htm#StartTopic=Content/sforce_api_calls_queryall.htm 

This was selected as the best answer
SuperfellSuperfell
There's no reliable way to access all of the records that getDeleted returns as deleted, some of them can be accessed via queryAll(), but some of them may of been flushed out of the recycle bin, and not all object types use the recycle bin.
balaji_sfbalaji_sf

Hi SimonF  & apexsutherland 

 

Thanks very much.

I tried the code and its worked very good :smileyhappy:

 

I had a very old PDF document and i was checking on it and there was no QueryAll information in it 

and the module "WWW::Salesforce" which i downloaded from cpan.org too didn't have the function QueryAll(), but i managed to create the function in my own by just replacing the "query" with "queryAll" and it worked fine. 

 

The SOQL is not so intelligent to give me back only the deleted records

as when i tried to give IsDeleted field in where clause i got error.

 

where i gave "select Id, IsDeleted From Contact where IsDeleted = 'true'"

and got the error 

"value of filter criterion for field 'IsDeleted' must be of type boolean and should not be enclosed in quotes at  "

 

If there is any way to filter out only the deleted records please let me know :)

or else i can manage by filtering after getting all the records. 

 

Thanks a lot again. 

 

Regards

Balaji

 

 

SuperfellSuperfell
select id, isdeleted from contact where isDeleted = true
apexsutherlandapexsutherland

balaji, you're pretty close, just get rid of the quotes around "true":

 

 

 

SELECT Id, IsDeleted FROM Contact WHERE IsDeleted = TRUE

 


 

apexsutherlandapexsutherland
Oops, guess I shouldn't leave a reply in edit mode for so long... :-P
balaji_sfbalaji_sf

It worked...

Thank you guys...

ChkiranChkiran

Hi Balaji,

I wanted to achieve same functionality of extracting the deleted records using SOQL in Apex. Can you help me in that? How did you achieved this functionality?

HariPHariP

I see records in Recycle Bin, but when I query using IsDeleted = TRUE, I get 0 results. Is there any setting I need to turn on? I am querying custom object records.

Sumit_SFDCSumit_SFDC
I am having the same problem like when I fire "SELECT Id, IsDeleted FROM Contact WHERE IsDeleted = TRUE", I get 0 result and when I fire "SELECT Id, IsDeleted FROM Contact WHERE IsDeleted = FALSE" then I get multiple records so, IsDeleted field is default false and in which case it is going to set true like when record is deleted or it is undeleted from Recycle Bin.Somone please help me for the same. Thanks in advance