0

I have files that were uploaded to the Asset Library for a Community by adding them to the Rich Content component on a Community page. When I look at the File's sharing settings, I can see that it is shared with the original Community. I want to be able to share it with a new Community. I don't see an option to do that. I can share it with libraries, etc. but not an option to share it with another Community. This is a problem because the original Community is deactivated and users don't have access to it anymore.

2 Answers 2

0

I would do a batchable that swaps 1 Id for the other. Something like this:

global class BatchableCommunityShares implements Database.Batchable<SObject>, Database.Stateful {
    global static Database.QueryLocator start(Database.BatchableContext ctx) {
        return Database.getQueryLocator([
            SELECT ContentDocumentId, LinkedEntityId, ShareType
            FROM ContentDocumentLink
            WHERE LinkedEntityId = 'OldCommunityId'
        ]);
    }

    global static void execute(Database.BatchableContext ctx, List<SObject> scope) {
        for (SObject obj : scope) {
            ContentDocumentLink cdl = (ContentDocumentLink) obj;
            cdl.LinkedEntityId = 'NewCommunityId';
        }

        update scope;
        // Disclaimer, it might not let you update the CDLs
        // If you have issues try to create new links and insert them instead
    }

    global static void finish(Database.BatchableContext ctx) {

    }
}

Then you can call it in anonymous apex:

BatchableCommunityShares batch = new BatchableCommunityShares();
Database.executeBatch(batch);

Alternatively, We use DBAmp to do large scale etl. Inserting/updating new contentdocumentlinks via etl would be easy enough.

1
  • Thank you! I will give it a try tomorrow. Commented Mar 8, 2019 at 0:06
-1

Each Content of Asset Library is a record of "Content Version" object; and for each Content Version record, there is ContentDocument record. Now, we can share a ContentDocument Record with user, group or community by creating a record of ContentDocumentLink.

Now you can move all file using batch or script using anonymous window.

Here are steps for POC:

  1. Get id of content version by reaching to Asset Library --> Open that file --> Copy Id from URL.

  2. Query ContentDocument Id as below

    String conDocId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id = '<content id from 1st step>'].ContentDocumentId;

  3. Get community Id and pass as LinkedEntityId below:

    ContentDocumentLink cdLink = new ContentDocumentLink (); cdLink.ShareType = 'V'; cdLink.ContentDocumentId = '<Document Id>'; //from second step cdLink.LinkedEntityId = '<community id>'; insert cdLink ;

3
  • Can you edit and add proper code formating? Commented Mar 7, 2019 at 19:02
  • My concern with your answer is that it's half manual half code; as written, it would require updating the shares one by one. Review my answer for a bulk approach options.
    – gNerb
    Commented Mar 7, 2019 at 19:07
  • Man! question was can we share files in community....my answer explained how can you do that ....given code is just for POC .... I doubt on people who mark such answer negative.
    – Ayub
    Commented Mar 8, 2019 at 6:29

You must log in to answer this question.

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