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
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.
Below are my author permission
Could someone please suggest what am I missing?