I am trying to upload a file from salesforce sites into Files and then relate it with a record using VF page.
i am able to upload the file and while creating a ContentDocumentLink i am getting this error.
Document: You don't have permission to share this file.
insert file;
ContentVersion cv = [SELECT id, ContentDocumentId FROM ContentVersion where Id = :file.Id];
ContentDocumentLink link = new ContentDocumentLink();
link.LinkedEntityId = sr.id; // this is record i want the file to be related to
link.ContentDocumentId = cv.contentdocumentid;
link.ShareType = 'V';
link.Visibility = 'AllUsers';
insert link;
Since the user who uploads the file is a site guest user, i am assuming thats the reason why i am getting this error.
Is there a way we can allow creation of ContentDocumentLink for site guest user? What i want is a way to associate the uploaded file with a record
Best Answer
Make sure that your guest site users has sharing record access to the entity the file is being shared with. I did a POC with a visualforce page exposed to public site and the guest user was able to create an account and upload a file to it without error.
Apex Controller
}
Visualforce Page