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.

 

 

Using Variable for Static Resource

Did you ever came across such requirement, when you have your static resource name in a variable and you have to use that variable to access static resource on your visualforce page. Lets see Using Variable for Static Resource.

Lets understand this with an example.
We have 3 static resources for 3 colours Red, Yellow and Green. On the Contact Object we have a pick-list field Colour (Colour__c) which have values Red, Yellow and Green.
Now we have a custom visualforce page and Apex class, the page shows some basic information of the contact record and it should show image stored in the static resource for the colour.

To achieve this We have to use

If we have name of static resource in an apex variable.

On the visualforce page we have to use

 

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 FISHERINV Function in Apex Salesforce

In last post (Excel FISHER Function in Apex Salesforce), we gone through the code for Excel FISHER function in apex. In this post we will see Excel FISHERINV function in apex salesforce. Basically FISHERINV function returns the inverse of the Fisher transformation.

Syntax of FISHERINV function is as follows in Excel

  • FISHERINV(y)
  • WHERE y is required
  • Value of y should be numeric.

APEX CODE

Let’s see the code for Excel FISHER function in Apex Salesforce.

Above code can be added in any apex class, after adding this code we can use it as per our requirement. Lets test it from developer console. Go to developer console and in Execute anonymous window paste the below code.

After executing above code snippet you will get below output.

Excel FISHERINV function in apex salesforce
Output in Developer console after executing code.

Thank you for reading 🙂

 

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.

Excel FISHER Function in Apex Salesforce

In this post we will see how we can write Excel FISHER function in Apex Salesforce. Before going to the apex code lets first see some details about FISHER function. This function returns the fisher transformation at x.

Syntax of FISHER function is as follows in Excel

  • FISHER(x)
  • WHERE x is required
  • Value of x should be greater than -1 and less than 1 i.e -1 < x < 1.

Now see the code for Excel FISHER function in Apex Salesforce.

Above code can be added in any apex class, after adding this code we can use it as per our requirement. Lets test it from developer console. Go to developer console and in Execute anonymous window paste the below code.

After executing above code snippet you will get below output.

Excel Fisher Function In Apex Salesforce
Output in Developer console after selecting Debug

Hope this code will save your time, if you need to implement FISHER function in salesforce.

Happy Coding 🙂
799 The Coder

See some more post for Excel function in Apex

Excel CORREL function in Apex Salesforce

Today we will see salesforce apex equivalent code for Excel CORREL function. Excel CORREL function in Apex Salesforce can be used if we need to perform same calculation on salesforce data as excel CORREL  function.

Syntax of CORREL function is as follows in Excel

  • CORREL(array1, array2)
  • WHERE array1 and array2 both are Required.
  • We must ensure that array1 and array2 are same in size.

See the code below, code has static methods written you can put them in your util class/helper class.

 

Once we have above methods in our code, we can use it 🙂 , Now lets test the method from developer console, open developer console and write below code.

When you execute the above code, you will get the output as follows.

####> correlationCoeffient = 0.997054485501581486225379535213640

correlationCoeffient = 0.997054485501581486225379535213640

Hope this will help you  🙂

See more Excel functions in apex salesforce code

Happy Coding !

799 The Coder

Excel INTERCEPT function in Apex Salesforce

Hello awesome Developers!!! This post will save your time if you are going to implement Excel INTERCEPT function in apex salesforce. In my previous post of excel function (Excel LINEST function in Apex Salesforce), we coded for LINEST function of excel.

Before we jump to code, lets have a quick view of INTERCEPT function.

Syntax of Intercept function is as follows in Excel

INTERCEPT(known_y’s, known_x’s)

WHERE Known_y’s  and Known_x’s  both are Required.

We must ensure that Known_y’s and Known_x’s size is same.

The above code snippet is a static method, you can put it any helper/utility class in salesforce.  See below a demo call to this method from developer console.

The output of the above code snippet from developer console will be below

INTERCEPT = 0.0483870967741935483870967741935484

Use it and save your time, in your saved time do some other creative coding 🙂 !!!

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 🙂

Getting length of integer part and fractional part in apex of a number type field salesforce

Sometimes we need to play with field (custom field or standard) properties in apex. If we need to find the integer part length in a “Number” type field, then there is no direct method in Describe Field Result (DescibeFieldResult) class. But we can find it using some other methods of DescribeFieldResult class.

Lets suppose we have a custom field of Number type with below properties.

“Test Number Field” (Test_Number_Field__c) Number(14, 2).

Number Options (Integer Part Length)
Number type field options.

So here from the above custom field we want to fetch Length property from number options i.e. 14. But when we use getPrecision() method we will get 16, and when we use getScale() method we will get 2.

Output of the above apex code snippet will be :

Apex Code Output.

So here we get the length of our Integer part in apex.

Conclusion

Integer Part Length = dfr.getPrecision() – dfr.getScale();

Fractional Part Length = dfr.getScale();

Total Length = dfr.getPrecision();

Finally if you need to do anything with the integer part length then grab the code from here and make it fast.

Happy Coding 🙂