1

I'm trying to display all the files of all the Groups to which a user belongs to.

i.e, if the user is a member of GroupA and GroupB, then I have to display all the files which belong to GroupA and all the files which belong to GroupB.

This is similar to 'FILES IN MY GROUPS' section in the standard Files tab.

Currently I am trying to use the 'ContentDocumentLink' object as shown below:

select Id, ContentDocument.title, ContentDocument.LastViewedDate, ContentDocumentId, ContentDocument.LastModifiedDate from ContentDocumentLink where LinkedEntityId =:groupId

Using the above query I can get all the files which belong to the group referred by the groupId variable.

When I try to query by giving a set of ids for 'LinkedEntityId' field in the where condition, then I'm getting an error saying that only a single id, ContentDocumentid or LinkedEntityId should be used with an equals operator.

Is there any other object that can be used for this? Or should the above query be changed? So how can I get a list of documents which belong to a list of groups? Need some help on this please.

0

If groupId is defined as set<Id> or list<Id>, then you should be able to use WHERE LinkedEntityId IN :groupId for the WHERE clause in your query to resolve the error message you're receiving.

  • I am trying the same using 'LinkedEntityId IN ' for the WHERE caluse, still the error persists. It is taking only a single LinkedEntityId with an equals operator. It is not accepting Set<Id>. – Naveen Apr 30 '15 at 9:55
  • I inadvertently omitted the colon in front of groupId and have corrected that. Did you use the colon? If so, what error message did you receive when using a set? As a "punt", have you tried using a list? Also, are you running this query as anonymous Apex or are you running it as part of a class? If you're doing the latter, you may want to isolate it and try running it as anonymous Apex. . – crmprogdev Apr 30 '15 at 18:52
0

The following code works fine and it gives all the files posted in all the Groups the user is associated with:

public List lstCollaborationGroupFeed {get;set;}

public List lstCollaborationGroupMember{get;set;}

/* Find all groups containing logged in user*/

    lstCollaborationGroupMember = [SELECT CollaborationGroup.Id, CollaborationGroup.Name FROM CollaborationGroupMember WHERE MemberId = :UserInfo.getUserId()];

    Set<Id> setMemberId = new Set<Id>();
    for(CollaborationGroupMember member : lstCollaborationGroupMember )
    {
        setMemberId.add(member.CollaborationGroup.Id);
    }

    lstCollaborationGroupFeed = [SELECT Title, ContentFileName, RelatedRecordId FROM CollaborationGroupFeed WHERE Type='ContentPost' AND ParentId IN :setMemberId];

lstCollaborationGroupFeed returns the details of all the files posted in the User's Groups.

  • This code is fine for a single file post. However, it won't work when there are multiple files posted in single post. Any ideas how to get all the files shared in a group with a filter on file type? – Mustafa Turab Ali Dec 10 '17 at 10:59

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.