Share Lightning Notes and Attachments with Community Users

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.

Visibility can have the following values.

  • 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.

Now your files attached to a record will be available to community if your community profile has access to that record.

 

 

Switch to Lightning Experience Using Apex Salesforce

In this post we will see how we can Switch to Lightning Experience Using Apex salesforce. When we are logged in salesforce org, then we can switch to lightning experience using UI. But what if we want to switch other users to lightning experience, so there are two ways.

  1. Individually login as all user and click on Switch to Lightning Experience : (That’s NOT a good Solution).
  2. Update all users from apex code. (That’s a Good Solution).

So what needs to be done for second option.  First see the “UserPreferencesLightningExperiencePreferred” field on  User Object. Then we need to set this field to true using code. See the code snippet below, you can execute this code from developer console.

Apex Code

Use this if you need to mass update users to switch to lightning experience.