[SalesForce] Case Email Attachments

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.

Best Answer

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'
Related Topic