I need to find whether records of a object type have any attachment on them or not. I see that below query doesn't work.

SELECT Id, ParentId FROM Attachment WHERE ParentId like '001%' .

Is there a way to find this? It is even better if there is way to get this in report or any standard fields.

Thank you!

  • @ArnoldJr. How do I create a formula field that indicates presence of Attachment? Please pass an example. – Saumya Ranjan Satapathy Aug 17 '18 at 18:59

You can filter your query on the field Parent.Type, whose value is an sObject name:

SELECT ParentId, Id FROM Attachment WHERE Parent.Type = 'Account'

That will get you back record-by-record level data on each Attachment and its parent.

Alternately, if what you want to know is "which kinds of objects in my org have attachments", you can do an aggregate query and group by Parent.Type:

SELECT Parent.Type, count(id) FROM Attachment GROUP BY Parent.Type 

That will give you back a table with values like

Parent.Type    count(id)  

Account        1

Contact        2

showing you which objects have attachments.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.