Formula Fields in Salesforce

HELLO Salesforce Thinkers, In our previous blog we learned about Roll-Up Summary Fields In Salesforce In this blog we are going to learn about “Formula Fields in Salesforce”.

Formula in Salesforce are used to calculate custom fields, validation rules, Flow logic etc.

Formula field are read-only fields that automatically calculate a value based on other fields or a formula.

Any change in expression or formula will automatically update the value of formula field.

A formula field can reference the value of another custom or standard field using a merge field.

Formula return types:

  • Checkbox : Returns a true or false value.
  • Currency : Returns a number in currency format of up to 18 digits with a currency sign.
  • Date : Returns a date, for example, The current date can be acquired by calling the built-in function Today(). 
  • Date/Time :  Returns the date and also the time of day including hour, minutes, and seconds.
  • Number : Returns a positive or negative integer or decimal of up to 18 digits.
  • Percent : Returns a number in percent format of up to 18 digits followed by a percent sign.
  • Text : Returns a text string.
  • Time : Returns data that represents a moment in time, without the date. A time field includes the time of day by hour, minutes, seconds, and milliseconds

How to create a Formula field?

We can create formula fields on any standard or custom object.

To create a formula, we have a formula editor,

The Formula Editor:

The formula editor comes in two flavors:

Simple and Advanced.

Advanced editor have more tools for us to create powerful formulas.

The text area is where we enter our formula.

The Insert Field button opens a menu that allows us to select fields to use in the formula.

The Insert Operator button opens a drop-down list of the available mathematical and logical operators.

In the Functions menu we view and insert formula functions.

Functions are more complicated operations that are pre-implemented by Salesforce.

Example of Functions:

TODAY() :  function returns the current date.

LEN(text) : function, for instance, finds the length of the text you input as a parameter.

The formula LEN(“Think”) returns a value of 5.

Once we’ve written a formula, we can use the Check Syntax button to Check the formula before saving.

If our formula has issues, the syntax checker alerts us to specific problems.

Example :

We will create a formula field to show student details based on a student First Name, Last Name , Date of Birth and Email.

Navigate to

Setup >> Object Manager >> Select the desired object

In this case we will select the “Student” object.

  • In the left sidebar, click Fields & Relationships.
  • Click New.
  • Select Formula and click Next.
This image has an empty alt attribute; its file name is new-fo.png
  1. Enter the Label.
  2. Select Text for the Return Type.
  3. Click Next.

4. It will navigate us to the Formula Editor.

Enter “Student Name” , click Insert Field on the Advanced Formula Editor. Select student >> FirstName, and LastName, click Insert.

Now insert the “BR()” function for the line break,

Similarly insert Date of Birth and Email.

the formula should be look like this..

Click the Check Syntax button. If no syntax errors, click Next.

Choose the user Profiles,

Click Next and Save.

Go to the Student page and verify the Student Details field is populating correctly.

In our next blog we will learn about Formula Operators and Functions.

Thanks for reading…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s