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
Syed Zaidi 52Syed Zaidi 52 

Weird Behavior - Deletion of Record

Unexpectedly werid behavior, I deleted an opportunity on frontend and queried for the deleted opportunity id, the record row was completed deleted from the opportunity table. When I restored the record from Recycle Bin, the row was back. I was expecting instead of record row completely disappearing from the table, the IsDeleted field would be updated. 

 
Best Answer chosen by Syed Zaidi 52
Maharajan CMaharajan C
Hi Syed,

It's true the Opportunity record row was completed deleted from the opportunity table. But the deleted records remain in the Recycle Bin for 15 days. So you can quey those data from the below ways

But we have the ALL ROWS in Soql query which will fetch the deleted records also with IsDeleted flag. But one problem is you cannot do it directly within the Query Editor of developer console but we have the workaround's in Developer Console. The workaround is to use the "Execute Anonymous Window".

1. Open "Enter Apex Code" window by selecting "Debug" -> "Open Execute Anonymous Window" menu
2. Enter the below code and output the result to the log. Check the "Open Log" checkbox. 
3. Click "Execute" to run your code and check the log file for your result.
List<Opportunity> allOpps = [SELECT ID,Name,IsDeleted FROM Opportunity where IsDeleted = True  ALL ROWS];
System.debug(allOpps.size());
System.debug( 'allOpps --> ' + allOpps);

We can also use the Apex Data Loader where we have to use (Export All) to query the deleted records also from Salesforce.

https://salesforce.stackexchange.com/questions/158862/how-to-use-all-rows/158867

https://developer.salesforce.com/forums/?id=906F00000008teaIAA

Thanks,
Maharajan.C

All Answers

Maharajan CMaharajan C
Hi Syed,

It's true the Opportunity record row was completed deleted from the opportunity table. But the deleted records remain in the Recycle Bin for 15 days. So you can quey those data from the below ways

But we have the ALL ROWS in Soql query which will fetch the deleted records also with IsDeleted flag. But one problem is you cannot do it directly within the Query Editor of developer console but we have the workaround's in Developer Console. The workaround is to use the "Execute Anonymous Window".

1. Open "Enter Apex Code" window by selecting "Debug" -> "Open Execute Anonymous Window" menu
2. Enter the below code and output the result to the log. Check the "Open Log" checkbox. 
3. Click "Execute" to run your code and check the log file for your result.
List<Opportunity> allOpps = [SELECT ID,Name,IsDeleted FROM Opportunity where IsDeleted = True  ALL ROWS];
System.debug(allOpps.size());
System.debug( 'allOpps --> ' + allOpps);

We can also use the Apex Data Loader where we have to use (Export All) to query the deleted records also from Salesforce.

https://salesforce.stackexchange.com/questions/158862/how-to-use-all-rows/158867

https://developer.salesforce.com/forums/?id=906F00000008teaIAA

Thanks,
Maharajan.C
This was selected as the best answer
Syed Zaidi 52Syed Zaidi 52
Thank you so much! I did forget to mention, my bad.. I know.., that I was querying within Azure DataFactory and I had to select Read Behavior to Query All to query deleted records. Your post lead me in the right direction.

User-added image
klingeltöne Coxklingeltöne Cox
Download the best ringtones at Bruitages (https://bruitagesgratuits.com/)
wilson davieswilson davies
Thanks For sharing this valuable information. if you like food this article is only for you guys. Wendy’s Breakfast Menu 2022 Wendy’s is an American multinational chain of fast-food restaurants. Wendy’s is the third-largest hamburger fast-food chain in the country.