for (SObject deletedObject : [SELECT Id, isDeleted, LastModifiedDate, parentId FROM Attachment WHERE isDeleted = true AND LastModifiedDate >= :timestamp ALL ROWS]) {

It appeared, that recently more than 50000 of Notes & Attachments were deleted. The trick is that all of them don't relate to my application - they wasn't linked to 'my' custom objects. I'm wondering, is there any way, I can query Notes & Attachments for specific sObjects?

  • Isn't the FROM clause working for you here? And what is the value in var "obj"?
    – Jagular
    May 4, 2015 at 14:00
  • Can you please dump your query without all the string concatenation? It is quite hard to read.
    – Adrian Larson
    May 4, 2015 at 14:28

1 Answer 1


It can be done. Here is some documentation on how it works. See the "Using the Type qualifier" section. This qualifier does not require polymorphism to be enabled in the org.

SELECT Id FROM Attachment WHERE Parent.Type = 'My_Object__c'


SELECT Id FROM Note WHERE Parent.Type = 'My_Object__c'
  • N.B. sadly (as of V41), this does not work: select id from FeedComment where Parent.Type = 'Account' - see workaround
    – cropredy
    Jan 12, 2018 at 18:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .