Formula Field in Salesforce

A Formula Field in Salesforce is used as a read-only field that derives its value from a formula expression you define. It is updated when any of the source fields change.

Salesforce provides us with a formula feature for creating formula fields. This feature has built-in functions and operators and a feature to rectify the formula. It is one of the important topics in Salesforce, so I decided to write a complete article on it.

In this Salesforce tutorial, I will explain the formula field and how to create a formula field in Salesforce Lightning and Classic Interface.

What is Formula Field in Salesforce

In Salesforce, the formula field is a feature that permits you to make custom fields whose values are calculated based on particular criteria or expressions. These formula fields are used in objects, reports, and workflows.

It is a read-only field, and the user can create a formula using functions, insert operators, and insert fields. The values of the formula field can be calculated from expressions defined by us.

If the value in the expression we can use is updated, the formula field value is automatically updated. Now, let’s move further and see how to create the formula field type in Salesforce Lightning and Salesforce Classic.

Read Salesforce Checkbox Formula

Create Formula Field in Salesforce

The creation of a formula field in Salesforce requires special attributes like editions and user permissions, and it is not available in all orgs.

You can also create a formula field in both the Salesforce Lightning and Salesforce Classic user interfaces. If you want to learn more, read the complete post.

See also  How to Set Length Limit for Text Area Long Field in Salesforce

How to Create Formula Field in Salesforce Lightning

Here we will learn how to create a formula field in Salesforce Lightning.

Consider a scenario where we are taking an account object and calculating the monthly commission of the account that is based on the annual revenue.

If the lower annual revenue gets the 0.15% commission, then the higher annual revenues get the 0.05% commission. For creating this formula we are using the formula data type that is present under the field and relationship.

The following are the steps:

1. Click on the gear icon –> Select the setup option –> Click on the object manager tab –> Select the account object.

How to create a formula field in Salesforce

2. Select the field and relationship option that is present on account page.

Create a formula field in Salesforce

3. We want to create a new field. Click on the new button.

Create a formula field in Salesforce Lightning

4. Choose the field type –> Select the formula field type –> Click on the next button.

Salesforce create a formula field

5. Now choose the output type. Fill the field label. Here, we are filling the field label as MonthlyRevenue, then fill the field name, and then clicking on the next option.

Choose the formula return type as a currency that can calculate a dollar or other currency amount and automatically format the field as a currency amount.

Salesforce Lightning create a formula field

6. Click on the advanced formula tab –> select the IF function –> Click on the insert selected formula button.

Here we set the formula as:

 IF( AnnualRevenue <=100000, AnnualRevenue*0.15/12, AnnualRevenue*0.05/12).

This formula shows that the annual revenue is above 100000. We will do the same calculation, but this time, the value of 0.05 represents a lower percentage. Then, we will divide by 12 again to represent the monthly amount.

How to create formula field in Salesforce

7. After creating the formula now established the field-level security. Select the profiles we want to grant edit access to this field via field-level security.

See also  How to Make Text Encrypted Field Required in Salesforce
How to create formula field in Salesforce Lightning

8. After establishing the field-level security. Now, we can add the page layout. Select the page layouts that should include this field.

Create formula field in Salesforce

9. After clicking on the save button. The field and relationship page is open and under this page, we can see that the monthly revenue formula currency field is created successfully.

Create formula field in Salesforce Lightning

This way, we understand how to create the formula type in Salesforce Lightning. Let’s Proceed and learn how to create the formula field type in Salesforce Classic.

How to Create Formula Field in Salesforce Classic

Here, we are creating the formula field type in Salesforce Classic

Consider a scenario where there is a user who wants to calculate how many days are left till the opportunity closes. For this, we want to create a simple formula that easily calculates the values.

After creating the field, the user can access the key information by simply adding the value to the opportunity page.

1. Log in to your Salesforce account –> Click on the Profile Picture –> Click on Switch to Salesforce Classic –> Go to the Setup –> Enter contract in Quick Find Box –> Click on the fields option.

Create a formula field type in Salesforce Classic

2. Now scroll to the bottom of the page there is a field and relationship section present. Click on the new option and choose the field type. Here, we are selecting the formula field. Click on the next button.

How to create formula field type in Salesforce Classic

3. Choose the output type. Fill the field label. Here, we are filling the field label as Days Remaining, then fill the field name, and then clicking on the next option.

Now, choose the formula return type. Here we are choosing the formula return type as a number that can calculate the numeric value.

Create formula field type in Salesforce Classic

4. Click on the advanced formula tab –> select the insert field –> select the contract and the end date of the contract.

See also  How to Set Default Value for Email Field in Salesforce

Now click on the insert operator button –> Select the subtract operator.

Select the functions –> select the Today() function –> Click on the insert selected formula button.

Now, the formula is generated as

EndDate—Today().
Salesforce Classic create formula field type

5. Now, establish the field-level security after creating the formula. Select the profiles we want to grant edit access to this field via field-level security.

How to create the formula field type in Salesforce Classic

6. After establishing the field-level security, we can add the page layout. Select the page layouts that should include this field.

Create the formula field type in Salesforce Classic

7. Now, we can add the page layout after establishing the field-level security. Select the page layouts that should include this field.

8. The field and relationship page is again open and under this page, we can see that the Days Remaining(Number) field is created successfully.

Salesforce Classic create the formula field type

So, with this, we have learned how to create a formula field in Salesforce Classic.

Conclusion

I hope now you have an idea of the formula field in Salesforce and how to create a formula in Salesforce.

I have also explained the different formulas by using different scenarios in the Salesforce interface.

You may like to read: