Activity Forums Salesforce® Discussions How can we query contentdocument which is inserted by community user only?

  • Saurabh

    Member
    March 23, 2017 at 1:23 pm

    Hi,

    There is no default sharing for an organization, so you have to add a record for it. If you wanted to share everything, you'd add a ContentDocumentLink record for the Org ID. Here is example code of doing that for all ContentDocuments:

    Id orgId = UserInfo.getOrganizationId();

    List<ContentDocumentLink> existingCDL =
    [SELECT Id, LinkedEntityId, ContentDocumentId, ShareType, Visibility
    FROM ContentDocumentLink Where LinkedEntityId = :orgId];

    Set<Id> alreadyLinked = new Set<Id>();
    for(ContentDocumentLink cd : existingCDL)
    alreadyLinked.add(cd.ContentDocumentId);

    List<ContentDocumentLink> cdl = new List<ContentDocumentLink>();
    for(ContentDocument cd : [Select Id From ContentDocument])
    {
    if(! alreadyLinked.contains(cd.Id))
    cdl.add(new ContentDocumentLink(
    LinkedEntityId = UserInfo.getOrganizationId(),
    ContentDocumentId=cd.Id,
    ShareType = 'C',
    Visibility = 'AllUsers'));
    }
    insert cdl;

    Hope it will help:

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos