SQRT() Function in Salesforce | Syntax, Examples, & Use Cases

I recently worked in a multinational company that manages its Customer Relationship Management and sales data, using Salesforce. One day, I was tasked with calculating the lead’s age squared to determine the lead’s experience level.

As a solution, I discovered that this Salesforce tool provides us with the function named “SQRT”, which helps calculate any given number’s positive square root.

In this tutorial, we will learn about the SQRT() function in Salesforce. We will also study the syntax for this function and numerous Salesforce examples from real-world organisations.

What is the SQRT() Function in Salesforce?

The SQRT() function in Salesforce is a built-in mathematical function used to perform calculations. In basic terms, the SQRT() function is used to find the positive square root of a given number.

In addition, the SQRT() function only supports numerical data types, such as Integers, Decimals, and Currency. However, an error will result if you attempt to use a text, date, or other non-numeric data type.

The syntax of the SQRT() function is as follows:

SQRT(number/field/formula)

The value for which we try to obtain a positive square value is represented by the parameter number/field/formula. The parameter value may take the form of a field, a fixed value, or an advanced formula.

For a better understanding of how the SQRT function works, let’s look at an example.

As I mentioned above, I need to find the lead age square to calculate the lead’s experience level. Therefore, I will utilise Salesforce SQRT() function for this. The formula is as given below:

SQRT(Age__c)

With this, we learned the syntax of the SQRT() function and an example. We’ll now look at how to use the  SQRT() function in Salesforce.

Use the SQRT() Function in Salesforce: Find Square Root

The following are the steps to use the SQRT() function in Salesforce:

  1. Open Salesforce Lightning mode. Next, click the “Gear Icon” in the top right corner of the page. Click Setup from the dropdown menu to continue.
SQRT Function in Salesforce
  1. The setup page opens when you select the Setup option. Here, the “Object Manager” is found in the Navigation Bar next to the Home tab. Click on it.
SQRT Function in Salesforce Example
  1. The object manager page opens when you click it. There are numerous objects seen here. Use the Quick Find search field to find the item on which we want to use the SQRT() function.
    • In this instance, I look for the “Product” object because I need to convert the product price to text and also concatenate the USD text to it.
    • Now, click the “Product” object to move to the product object page.
SQRT Function in Salesforce Lightning
  1. Select Field & Relationship and click the “New” button to create a new field.
SQRT Function in Salesforce Lightning Example
  1. The field type page opens when you click the new button. The page contains a wide variety of field types. In this case, I chose the “Formula” field type, as I want to use the SQRT function in the advanced formula.
    • Click the “Next” button to move on to the next step.
Salesforce SQRT Function
  1. Enter the information now by filling out the “Field Label” and the “Field Name”. I have provided “Shipping Price” in the field label.
    • Choose the “Output Data Type for the field that is going to store the outcome. In this case, I set the “Decimal Place” to 1 and checked the radio button next to the “Currency” data type to convert the formula’s return type to currency.
    • Move to the next step by clicking the “Next” button.
Salesforce SQRT Function Example
  1. Enter the SQRT() function formula in the advanced formula editor. In this case, I want to estimate the shipping price based on the product weight. The formula is as follows:
SQRT(Weight__c)

Here, we pass the product “Weight__c” field to the SQRT function to calculate the estimated shipping price based on the weight.

  1. Select “Check Syntax” to validate the formula and ensure there are no errors.
    • Enter the “Description” and “Help text” as well as “Handle the empty field” which is optional information.
    • Click the “Next” button to proceed to the security step for the formula field.
SQRT() Function in Salesforce
  1. In this step, establish Field-Level Security. Choose the profiles to which we wish to grant field-level security edit access to this field. If field-level security is not added, the field will be hidden from all profiles.
    • Because I want it to be visible to all profiles, I have chosen “Visible” in this instance. After that, click the “Next” button located at the top.
Salesforce Lightning SQRT Function Example
  1. Add the custom field to the “Page Layout” after configuring the field-level securitySelect the page layout that includes this field. The field would not appear on any pages unless we chose a page layout.
    • Click the “Save” button to save the formula field.
How to use SQRT Function in Salesforce Lightning

We can use the formula field once we have created it. Let’s look at an example:

  • Open the “Product” Tab and create a new product with the field “Weight”.
  • The “Shipping Price” field, which displays the SQRT() function output, appears when you click on the Details Section.
How to use SQRT Function in Salesforce Lightning

As a result, we now understand how to use the SQRT() Function in Salesforce.

Conclusion

We have learned the Salesforce SQRT() function. Moreover, we have learned the SQRT() function in Salesforce syntax and several real-world business scenarios.

In addition, we also covered the steps for using the SQRT() Function in Salesforce.

You may also like:

Agentforce in Salesforce

DOWNLOAD FREE AGENTFORCE EBOOK

Start with AgentForce in Salesforce. Create your first agent and deploy to your Salesforce Org.

Salesforce flows complete guide

FREE SALESFORCE FLOW EBOOK

Learn how to work with flows in Salesforce with 5 different real time examples.