2

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!

1
  • @ArnoldJr. How do I create a formula field that indicates presence of Attachment? Please pass an example. Commented Aug 17, 2018 at 18:59

1 Answer 1

5

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.

0

You must log in to answer this question.

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