[SOLVED by removing trigger on ContentDocumentLink]
I am implementing uploading files as ContentDocument. For System Administrator all works good, but for non-registered site user it does not work.
Creation of ContentVersion
is good, but it fails at creation of ContentDocumentLink
with exception INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY
.
Btw site user can successfully create all other objects (Opportunity, Account etc..)
I removed all dml except this one. I hardcoded Ids of existing ContentDocument
and existing Opportunity
. Owner of ContentDocument and Opportunity records is Site Guest User. And it fails only at creating ContentDocumentLink
And Query for both Opportunity and ContentDocuments returns existing data. So User has access to both objects.
// ...
ContentDocumentLink link = new ContentDocumentLink(
ContentDocumentId = 'xxxxxxxxxxx',
ShareType = 'I',
LinkedEntityId = 'xxxxxxxxxxxx'
);
insert link;
// ...