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
TehNrdTehNrd 

How to query isDeleted with apex SOQL?

I know I have to use query all or all rows or something but I can't figure it out. I always get the error: "MALFORMED_QUERY - ALL ROWS not allowed in this context". What does this mean?

I've tried with no luck:
SELECT Id, isDeleted FROM OpportunityLineItem WHERE isDeleted = true All ROWS
SELECT Id, isDeleted FROM OpportunityLineItem WHERE isDeleted = true QUERY ALL

Thanks,
Jason


mikefmikef
the syntax is All ROWS, try adding a colon to the where statement.
WHERE isDeleted =: true All ROWS
JerryJosephJerryJoseph
how can i run this apex soql?
mikefmikef
SOQL is the Force.com query language and can be run in the Force.com platform.

The web service, Ajax, and Apex all support SOQL.

For testing you can use the Force.com develoment tools, http://wiki.apexdevnet.com/index.php/Tools.
TehNrdTehNrd
So I am having a hard time understanding how this isDelete field works. 

I have an Opportunity:
ID: 006R0000002Kpjl

This opp has two oppLines that have not been deleted. I am using the APEX/Soql Explorer to run this query and I get the two lines, and isDeleted = false:

Select Id, IsDeleted, OpportunityId, UnitPrice from OpportunityLineItem where OpportunityId = '006R0000002Kpjl'

I then delete the items and run this again. In the tool there is the options to "Query" and "Query All" no matter what I do I can't get the lines items to return in the results.

Thoughts?
TehNrdTehNrd
Figured it out.

If a opportunity is deleted the child line items are flag as isDeleted but if you delete a line item it is deleted deleted and is not coming back.

-Jason
mikefmikef
cool, sorry about my other post about = : I thought you were having issues with Queries is Apex, I should have known you already know that. :)
TehNrdTehNrd
No worries. I actually wasn't that clear in my first post.
TehNrdTehNrd

Just did some more testing and this syntax works fine.

 

 

select Id, isDeleted from Contact where AccountID = 'a0750000003erMU' ALL ROWS

 

 

Dan RamirezDan Ramirez
@TehNrd I just tried to do a similar SOQL with deleted contacts using the following query:
SELECT Id, Name
FROM Contact
WHERE IsDeleted = true
ALL ROWS

And I too get the following error message:
MALFORMED_QUERY: ALL ROWS not allowed in this context
Do you know why this is happening? and/or what I can do to get the query to work? I've tried it without the "All Rows" statement and I get 0 records even though I know I have deleted contacts in my recycle bin. Thanks!
Prakhyat sapraPrakhyat sapra
Hi guys,I just want to confirm that is there any wat to get these records back in the salesforce?