When I run

select count() from attachment ; it returns 3099 .

when I run

Select Name,Id,ParentId,Parent.Type,Owner.Name,Owner.Id ,Owner.IsActive ,ContentType,isPrivate from Attachment ; it return 3099

when I run

Select count(Parent.Type) from Attachment ; -- it return 3091

when I run

Select Name,Id,ParentId,Parent.Type,Owner.Name,Owner.Id ,Owner.IsActive ,ContentType,isPrivate from Attachment order by Parent.Type; it return 3050

I played with SOQL above today and I have no idea why it returns data count differently.Which one is accurate?

The aggregate value still return null but total count is different between select count() from attachment.

enter image description here


1st and 2nd query returns number of attachments, 3rd query is returning attachments having Parent.Type != null so you are getting count different

| improve this answer | |
  • Attached picture it still return null, in my programming logic I put filter to get parent.Type=null and it returns 8 data.But still not match with total data. – unidha Aug 24 '16 at 11:47

After I digged the all the data return by select Id from Attachment, I found out the missing number is coming from Parent.type='00X' which are Unfiled Public Email Templates.


However if we try to manually query it

Select Id from Attachment where Parent.Type='00X , it will return 0 data.

Also some of Parent.Type is null but actually it is 'Event'.

I hope they have documentation on this.

| 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.