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.

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
-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? Mar 7 '19 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
    Mar 7 '19 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
    Mar 8 '19 at 6:29

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.