I'm attempting to pull case feeds with their associated attachment's meta-data. What I'd like to do is pull feed attachment data like I am in the attached query, however I'd like to add another field in the 'sub-query' that is something along the lines of Record.PathOnClient or RecordId.PathOnClient. Very similar to the way I'm pulling the name of the contact who inserted the comment. The documentation doesn't have any of the reference information available; just that RecordId relates to one of three fields (one being ContentVersion)

SELECT Body, CommentCount, CreatedById, CreatedDate, Title, Type, Id,
    LastModifiedDate, InsertedBy.Name,        
     FROM FeedAttachments WHERE Type IN ('Content') AND IsDeleted = false)
FROM CaseFeed WHERE ParentId = ? 
    AND Type IN ('ContentPost', 'TextPost', 'CaseCommentPost') 

What am I missing?

I tried

  • Would you be able to just include a second query? In what context are you trying to pull this data?
    – Adrian Larson
    Commented Jun 12, 2017 at 21:26
  • I mean I could, but I'd have to have a query for every attachment. This is going to be a view / edit page for cases. I want to list the case and all the associated comments. So, I'm pulling the associated feed records and I just want to have the attachment name. Then, I can create a link to download it with the files original name. The problem is I can't seem to get the attachments name because I can't nest the sub-queries and can't figure out the non-child relationship syntax (if it even works for that field)
    – polygone
    Commented Jun 12, 2017 at 21:31
  • You wouldn't need one per, just one more overall. I'll write up how you would do that, maybe it will help. Do you want RecordId to match CaseFeed.ParentId or CaseFeed.Id?
    – Adrian Larson
    Commented Jun 12, 2017 at 21:32
  • I need the ContentVersion object that the RecordId Relates to. So, in the sub-query I have, I would have tried SELECT RecordId, RecordId.PathOnClient ... or something similar to that, but I don't think that works. RecordId shouldn't have anything to do with the CaseFeed (as far as I know) Edit: I think you meant to write the query you mentioned ... CaseFeed.Id in that case
    – polygone
    Commented Jun 12, 2017 at 21:36

1 Answer 1


I recommend you add a query. You can use a simple grouping strategy so that you have the corresponding records for each feed:

List<CaseFeed> feeds = [/*query from OP*/];
Set<Id> feedIds = new Map<Id, CaseFeed>(feeds).keySet();
Map<Id, List<ContentVersion>> feedIdToContent = new Map<Id, List<ContentVersion>>();
for (ContentVersion content : [
    SELECT RecordId, PathOnClient
    FROM ContentVersion
    WHERE RecordId IN :feedIds
    if (!feedIdToContent.containsKey(content.RecordId))
        feedIdToContent.put(content.RecordId, new List<ContentVersion>());

If you wanted to filter on RecordId matching the ParentId, you would need to tweak the collection approach slightly:

Set<Id> parentIds = new Set<Id>();
for (CaseFeed feed : feeds)
for (ContentVersion content : [
    SELECT RecordId, PathOnClient
    FROM ContentVersion
    WHERE RecordId IN :parentIds
    // same grouping approach

You must log in to answer this question.

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