I have below apex method code which is executed by community guest users for the public-facing website.

PageReference pageRef = Page.myVFPage;
    ContentVersion conVer = new ContentVersion();
            conVer.ContentLocation = 'S'; 
            conVer.PathOnClient = PDF_TITLE_EXT; 
            conVer.Title = PDF_TITLE; 
            conVer.VersionData = pageRef.getContentAsPdf();
            conVer.Origin = 'H';
            insert conVer;

Above works fine and save the file under-owned by me tab as shown in the below image

enter image description here

now I need to display this file so creating a content distribution record

ContentDistribution contentDist              = new ContentDistribution();
        contentDist.Name                             = 'customName';
        contentDist.ContentVersionId                 = contentVersionId;
        contentDist.PreferencesAllowViewInBrowser    = true;
        contentDist.PreferencesLinkLatestVersion     = true;
        contentDist.PreferencesNotifyOnVisit         = false;
        contentDist.PreferencesPasswordRequired      = false;
        contentDist.PreferencesAllowOriginalDownload = true;
insert contentDist;

executing above code as site guest user gives below error

{"status":500,"body":{"fieldErrors":{},"pageErrors":[{"statusCode":"INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY","message":"insufficient access rights on cross-reference id"}],"index":null,"duplicateResults":[]},"headers":{}}

I have tried creating content document link

ContentDocumentLink conDocLink = new ContentDocumentLink();
        conDocLink.LinkedEntityId = [SELECT Id FROM Account WHERE Name =:accountName]?.id;
        conDocLink.ContentDocumentId = conDocId;  //ContentDocumentId Id from ContentVersion
        conDocLink.shareType = 'V';
        conDocLink.visibility = 'AllUsers';
        insert conDocLink;

it inserts content link but inserting content distribution still gives the same error

Beow are my content delivery settings.

enter image description here

Below are my author permission

enter image description here

Could someone please suggest what am I missing?

  • Is apex code executed via lwc component or vf page? Commented Jul 4, 2021 at 13:29
  • Also owned by me there is it your user? Commented Jul 4, 2021 at 13:30
  • 1
    lwc component calling the vf controller, yes it is my user and any content version I create from guest user showing under own by me (I am system administrator)
    – gs650x
    Commented Jul 4, 2021 at 13:38
  • 1
    and also I am the default owner of the records created by guest users.
    – gs650x
    Commented Jul 4, 2021 at 13:57
  • Are you creating the records in guest user context from incognito browser? Commented Jul 4, 2021 at 14:01

2 Answers 2


I think oneenter image description here thing missing is adding a user as Author in Library. Go to Files > Library > Manage Members > Add user as Author. enter image description here

  • Thank you for your answer, but whatever guest user add to files shows under owned by me not under asset library, could you please tell me what should I do so that content version show under assest library instead of owned by me?
    – gs650x
    Commented Jul 5, 2021 at 3:34
  • Actually, I have tried that but when I query content workspace as system admin I get the results but when I query workspace as guest user, it throws exception that list has now row to assign to sObject
    – gs650x
    Commented Jul 5, 2021 at 3:43
  • I also tried by hard coding the workspace id of asset library now it throws insufficient access issue while inserting content document link record.
    – gs650x
    Commented Jul 5, 2021 at 5:02

@gs650x I have the same problem as you, according to my research, guest users can't create public link(ContentDistribution) since winter'19. Is that correct? Do you have a solution for this problem?

You must log in to answer this question.

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