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.

 

 

SOQL query to fetch all fields of an object

Just in case if we need to fetch all fields with SOQL in salesforce, what we will do? SOQL query to fetch all fields of an object can be achieved with below approach.

  1. Write each field in SOQL
  2. Go to developer console, open the object, select all fields and click on query, then copy all fields from query tab.
  3. Write code in such a way that it will fetch all fields.

Now lets consider pros and cons of each approach. In first approach “Write each field in SOQL”, if any new field is created in future then code update required. Also we its time taking if there are too many fields.

In Second Approach, if any new fields is created in future then code update required.

In Third approach where we are writing code such that code doesn’t need any update if any new field added.

Apex Code

Below is the apex method for getting SOQL query to fetch all fields of an object.

This method can be used as below.

Hope this will help and increase productivity of developers.

 

Excel LINEST function in Apex Salesforce

As a developer we sometime need to implement excel function in code for meeting client’s requirement. Here I will share code for Excel LINEST function in apex. You can check LINEST function/method of excel here.

See below code method, you can use it in your apex class.

It will save your time if you need to write it from scratch in apex. I am open for your valuable feedback.

Happy Coding 🙂