I am trying to retrieve attachments for emails on a specific case using SOQL and not having much success. I am trying using following

Select id, Name, Body, ContentType, parentId from Attachment where parentId in (select (select id from EmailMessages) from Case where Id = '5005700001Oz5na')

I get unknown parsing error I guess because of the inner select statement. Can anyone point me in the right direction.

  • Whoa! Your soql looks confusing. First you can't have nested sub queries ( child access allowed to single child level) and then even your sub query looks incorrect. Check this link for soql relationship basics.
    – Mahmood
    Commented Feb 27, 2017 at 20:25

1 Answer 1


You can't use a sub-query in a Left Inner Join. If you want to get Attachment records looking up to EmailMessage records under a specific Case, you would use a direct query on EmailMessage in your join filter:

SELECT ... FROM Attachment WHERE ParentId IN (
    SELECT Id FROM EmailMessage WHERE ParentId = '5005700001Oz5na'

You must log in to answer this question.

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