There are many kinds of fields that can be created to help organize your data within your CRM. Among one of the most challenging types is the Formula Field. This is because formula fields require a more advanced knowledge of how fields interact with one another and how they are labeled. This is similar to functions within Excel.
This article will go over:
What is a formula field
How do I create a formula field
Testing your formula
What is a Formula Field
A formula field is a field created to do a number of functions that include, but are not limited to:
Calculate a total using other field values for reference
Display data found on other related objects
Roll up totals from child records
Note: formula fields are not editable on the page layout and cannot be overridden unless written within the formula itself.
How to Create a Formula Field
As with any other custom Salesforce field, formula fields are created by following just a handful of steps:
Navigate to the Object Manager from Setup – select the object you wish to create the Formula Field on.
Click New in the Field and Relationship section.
Select Formula as the field type.
Formula Output Data Type
Once a formula field is selected, you should choose which data type is most suitable the type of information you would like to display. This will be the format of the outcome of your formula.
Layout and Features
After you have selected your data type, you will be presented with the formula creation page (I would always advise clicking on the Advanced tab). There are various features you can take advantage of here for building both simple and complex formulas to display different sets of data on your object:
Insert Field: Insert fields from your object and related objects here. Standard field syntax looks like the Amount field, custom fields will always have “__c” appended to the end.
Operators: Operators allow you to test and evaluate data in different ways – for example, performing simple mathematical equations or concatenating text .
Functions: Functions allow you to transform data, perform calculations, or test data in a more comprehensive way than you can with operators. While you will find common functions such as IF(), there are Salesforce-specific ones as well, like ISPICKVAL() – used when working with picklist fields within a formula.
Testing your Formula
The “Check Syntax” button at the bottom left of the formula box is just one of the ways you can check your formula is correct. While the syntax may be spot on, mistakes like referencing the wrong field or not capturing the entire requirement can still happen.
Be sure to:
Test in Sandbox if possible – create enough test records in your developer sandbox to cover the different scenarios.
It’s important for the impacted users to confirm the formula works as expected, especially if it is a complex one which will be widely used.
Once in production, test this formula again by going into a record and confirming the field yields favorable/expected results– this is recommended for anything and everything that is released to the production environment.