Having issue accessing images, files, Notes or Attachments on the community ? Let’s find the reason and the solution to make it work. Lets Share Lightning Notes and Attachments with Community Users.
See Salesforce Files for more details about how notes and attachments are stored in Saleforce. To check the data model of new file system check Content Objects. Once you are get familiar with the content objects data model, you will know that ContentDocumentLink plays role for access and sharing.
Visibility field of ContentDocumentLink object Specifies whether file is available to all users, internal users, or shared users.
- AllUsers—The file is available to all users who have permission to see the file.
- InternalUsers—The file is available only to internal users who have permission to see the file.
- SharedUsers—The file is available to all users who can see the feed to which the file is posted. SharedUsers is used only for files shared with users, and is available only when an org has private org-wide sharing on by default. The SharedUsers value is available in API version 32.0 and later.
If we set visibility to AllUsers than files, Notes and Attachment will be visible to community users also. In order to set the visibility to AllUsers we need to create an Apex Trigger on the ContentDocumentLInk object.
1 2 3 4 5 6 7 8 9 |
trigger ContentDocumentLinkTrigger on ContentDocumentLink (before insert) { for(ContentDocumentLink cdl : Trigger.new){ if(cdl.LinkedEntityId != null && Schema.YOUR_OBJECT_API_NAME.SObjectType == cdl.LinkedEntityId.getSobjectType()){ // Check if contentDocumentLink is for your specific object or not. cdl.visibility = 'AllUsers'; } } } |
Now your files attached to a record will be available to community if your community profile has access to that record.