You need to sign in to do that
Don't have an account?
Anu Maniappan
Querying all the files from a list of groups for a particualr user
Hi All,
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.
Thanks,
Anu
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.
Thanks,
Anu
I have written piece of code,
Kindly let me know whether its suffice your problem.
Class:
public List<CollaborationGroupFeed> lstCollaborationGroupFeed {get;set;}
public List<CollaborationGroupMember> lstCollaborationGroupMember {get;set;}
public void init()
{
/* 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];
}
Page:
<apex:pageBlock>
<apex:pageBlockTable value="{!lstCollaborationGroupFeed }" var="feed">
<apex:column headerValue="File Title">
<apex:outputText value="{!feed.Title}"></apex:outputText>
</apex:column>
<apex:column headerValue="File Name">
<apex:outputText value="{!feed.ContentFileName}"></apex:outputText>
</apex:column>
<apex:column headerValue="File Id">
<apex:outputLink value="/{!feed.RelatedRecordId}">{!feed.RelatedRecordId}</apex:outputLink>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
Warm Regards,
Darshan Shah
All Answers
Just give single user Id in where condition as underlined below.
You will get all the files containing the that perticular user.
select Id,ContentDocument.title,ContentDocument.LastViewedDate,ContentDocumentId,ContentDocument.LastModifiedDate from ContentDocumentLink where LinkedEntityId =:userId
Warm Regards,
Darshan Shah
If I give LinkedEntityId=:userId, then it will return all the documents that user is associated with.
I dont need all those documents associated with that user. I need only the documents of the groups that user belongs to.
I have written piece of code,
Kindly let me know whether its suffice your problem.
Class:
public List<CollaborationGroupFeed> lstCollaborationGroupFeed {get;set;}
public List<CollaborationGroupMember> lstCollaborationGroupMember {get;set;}
public void init()
{
/* 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];
}
Page:
<apex:pageBlock>
<apex:pageBlockTable value="{!lstCollaborationGroupFeed }" var="feed">
<apex:column headerValue="File Title">
<apex:outputText value="{!feed.Title}"></apex:outputText>
</apex:column>
<apex:column headerValue="File Name">
<apex:outputText value="{!feed.ContentFileName}"></apex:outputText>
</apex:column>
<apex:column headerValue="File Id">
<apex:outputLink value="/{!feed.RelatedRecordId}">{!feed.RelatedRecordId}</apex:outputLink>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
Warm Regards,
Darshan Shah