How to Create Formula Field Type in Salesforce

In this Salesforce tutorial, we will discuss how to create the formula field type in Salesforce. For creating the formula field Salesforce provides us with the formula feature this formula feature has inbuild functions and operators. This formula field has a feature to rectify the formula.

For example, there is a Salesforce company and lots of employees are working in different departments but there is only one account manager for all the departments who can handle the account of the employee. This account manager pays the salary of all the employees on time.

At once they did a mistake due to lots of responsibilities, so the company board members thought that hiring one more employee that can share the responsibility of the account manager and they both use the formula field for calculating the annual revenue of the company after paying the salary of all the employees.

For calculating the annual revenue of the company they first need to create the formula field type. So, they use the formula data type that is present under the fields and relationship.

Let’s go into more detail about creating the formula field type in Salesforce Lightning and Salesforce Classic.

Formula field type in Salesforce

A formula field is defined as a read-only field and the user can use the function, insert operators, and insert field for making the formula. The values of the formula field can be calculated from expressions that are defined by us.

If the value in the expression that we can use is updated, the formula field value is automatically updated.

For example, we create a formula field that calculates the commission, that is based on the annual revenue field on the account, we calculate the custom calculation that calculates the monthly commission on the account based on the annual revenue.

But at the special requirement, the company wants to implement different percentages that are depending on the threshold. If the total annual revenue of the account is above 100000 then the agent should get a lower percentage.

Now, let’s move further and see how to create the formula field type in Salesforce Lightning and Salesforce Classic.

Read Salesforce Checkbox Formula

How to create a formula field type in Salesforce Lightning

Here we are creating a formula field type in Salesforce Lightning. Here we take an example 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.

If you want to learn how to create a formula field type in salesforce lightning, follow these steps:

Step-1: Login into the Salesforce account, the Salesforce Lightning version is open. Here we can create the formula field. For creating the formula field we go to our gear icon(⚙️).

Click on the gear icon, and the drop-down list of the gear icon is open. Under this gear icon there are two options. The first one is Setup and another one is Service Setup. Here we click on the Setup option.

After clicking on the Setup option, the Setup page is open. Under this setup page, the object manager tab is present on the nav bar. Click on the object manager tab.

How to create a formula field type in Salesforce

Step-2: After clicking on the object manager, the object manager page is open. Under this object manager page, we can see that lots of objects are present. Select one of the object and here we want to select the account object.

The account object is the first object on this object manager page. So we don’t need to search for this object in the search box.

How to create a formula field type in Salesforce Lightning

Step-3: After clicking on the account object, the account object page is open. Here we can read the details related to the account. And on the left-hand side of the page, there is a separate section of details and under these details, there is a field and relationships option.

We are selecting this field and relationship option for creating the fields and creating the relationship between the fields and the object.

Create a formula field type in Salesforce

Step-4: Here we can see that the account field and relationship page is open. Under this field and relationship page, there are lots of fields present, but we want to create a new field.

So, for creating the new custom field. Click on the new button that is present in the middle of the field and relationship page.

Create a formula field type in Salesforce Lightning

Step-5: After clicking on the new button. The account’s new custom field page is open. Here we are choosing the field type and specifying the type of information that the custom field will contain.

Here we are choosing the formula data type that can read-only field that derives its value from a formula expression you define. The formula field is updated when any of the source fields change. Click on the next button.

Salesforce create a formula field type

Step-6: After clicking on the formula data type, now choose the output type. Here we first fill the field label as MonthlyRevenue and then fill in the field name and the field mane field is automatically filled by a simple click on the field.

After filling the complete information related to the output type, now choose the formula return type. Here we are choosing 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.

After choosing the formula return type click on the next button that is present at the to and the bottom of the page.

Salesforce Lightning create a formula field type

Step-7: Here we can enter the formula and check the syntax to check the errors. Click on the advanced formula subtab to use additional fields, operators, and functions.

Here we are using the advanced formula subtab by simply clicking on the advanced formula tab option. On the right side select functions and here we are selecting the if function and clicking on the insert selected formula button.

And the displayed value of the if the function is if open parentheses, logical test value, value if this test is true, and what the value should be if the test result turns out to be false and then close the parentheses.

In the text area select the logical test section of the formula and insert the field you want to check against. We want to check the annual revenue on the account object. So choose an account, then annual revenue and this field name is populated in the text area.

Now insert the logical test in our case below or equal to 100000, the next section of the formula is the value if the test is true. We will insert a calculation that will multiply the revenue by 0.15 and then divide it by 12 to represent the monthly amount.

For the last section, the value of false. In other words, if the annual revenue is above 100000 we will do the same calculation. But this time the value of 0.05 represents a lower percentage and then divide by 12. Again to represent the monthly amount.

Before saving the formula, check the syntax structure at the bottom to see if anything needs to be amended. If not the syntax is correct then click on the next button.

How to create formula field type in Salesforce

Step-8: 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.

The field will be hidden from all profiles if we do not add to it field-level security. Click on the visible checkbox of the field-level security for the profile and then click on the next button which is present near the previous option.

How to create formula field type in Salesforce Lightning

Step-9: After establishing the field-level security. Now we can add the page layout. Select the page layouts that should include this field. The field will be added as the last field in the field two-column section of these page layouts.

This field will not appear on any pages if you do not select a layout. To change the location of this field on the page, we will need to customize the page layout. Click on the save button.

Create formula field type in Salesforce

Step-10: 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 type 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 a formula field type in Salesforce Classic

Here we are creating the formula field type in Salesforce Classic. Let us take an example there is a user who wants to calculate how many days are left till the opportunity closed. 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.

Step-1: Login into the Salesforce Account, when we log in we directly reach the Salesforce Lightning account. But we want to move to the Salesforce Classic account for this click on the profile picture.

And under this profile picture, there is an option to switch to salesforce classic. Click on the switch to the Salesforce classic option. After clicking on the switch to the Salesforce Classic option, we are moving to the Salesforce Classic version.

Here we click on the username drop-down arrow, and the drop-down list is open under this drop-down arrow. Under this List, there is a setup option here, we are clicking on the setup option.

How to create a formula field type in Salesforce Classic

Step-2: After clicking on the Setup option the Setup page is open, Under this setup page, there is Quick Find Box, enter the contract in this Quick Find box. The Contract object comes at the top. Click on the drop-down arrow of the contract object. The drop-down list is open.

Under this contract drop-down list, there is a fields option. Click on the fields option.

Create a formula field type in Salesforce Classic

Step-3:  After clicking on the Contract object, the Contract custom object page is open. Now scroll to the bottom of the page and see the contract custom field and relationships section here. And we want to create a new custom field related to the contract by simply clicking on the new button.

Salesforce Classic create a formula field type

Step-4:  After clicking on the new button, the new custom field page is open. Here we can choose the field type by specifying the type of information that the custom field will contain. Here we are selecting the formula field. Click on the next button.

How to create formula field type in Salesforce Classic

Step-5: After clicking on the formula data type, now choose the output type. Now fill the complete information related to the contract’s new custom field. First, fill the field label as Days Remaining and then fill in the field name, and the field mane field is automatically filled by a simple click on the field.

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

After choosing the formula return type click on the next button that is present at the top and the bottom of the page.

Create formula field type in Salesforce Classic

Step-6: Here we can enter the formula and check the syntax to check the errors. Click on the advanced formula subtab to use additional fields, operators, and functions. Here we are using the advanced formula subtab by simply clicking on the advanced formula tab option.

On the right side, there is the insert field button, click on that button the insert field dialogue box is open. Here we select the contract and the end date of the contract.

After that click on the insert operator button, the drop-down menu is open and from the menu here we are selecting the subtract operator.

On the right side select functions and here we are selecting the Today() function and clicking on the insert selected formula button.

Now the formula is generated as EndDate – Today() and shown under the Formula dialogue box. Before saving the formula, check the syntax structure at the bottom to see if anything needs to be amended. If not the syntax is correct then click on the next button.

Salesforce Classic create formula field type

Step-7: Now established the field-level security after creating the formula. Select the profiles we want to grant edit access to this field via field-level security. The field will be hidden from all profiles if we do not add to it field-level security. 

Click on the visible checkbox of the field-level security for the profile and then click on the next button which is present near the previous option.

How to create the formula field type in Salesforce Classic

Step-8: Now we can add the page layout after establishing the field-level security. Select the page layouts that should include this field. The field will be added as the last field in the field two-column section of these page layouts.

This field will not appear on any pages if you do not select a layout. To change the location of this field on the page, we will need to customize the page layout. Click on the save button.

Create the formula field type in Salesforce Classic

Step-9: After clicking on the save button. The field and relationship page is open and under this page, we can see that the DaysRemaining(Number) field is created successfully.

Salesforce Classic create the formula field type

In this way, we learned how to create the formula field type in Salesforce Classic.

Conclusion

If we need to access and enter the data without doing the bundle of calculations. There is a helpful tool that Salesforce provides us to control how our data is displayed. When the user want to calculate the two numerical number and also divide them and firn the percentage then this formula field helps the users and make the calculation easier.

After reading the complete blog, I hope you learned how to create the formula field type in Salesforce. And I have also explained all the steps of formula field type in Salesforce Lightning and Salesforce Classic.

You may like to read: