About Us


Are you looking for Salesforce Consulting Services? As Salesforce Implementation Partner, We provide services of · Salesforce Communities Cloud · Marketing Cloud · Idea to AppExchange Listing · APIs and Integrations · Gorgeous UX · Solution/Security/AppExchange Review · Salesforce Custom Development · Salesforce Mobile Solutions, And so much more!!

Working Hours

🕒 Monday to Friday: 9 AM – 10 PM IST

Top
Using formula fields in Salesforce

Using Formula Fields in Salesforce

Introduction

Formula fields are custom fields that automatically provide results based on records and related records. They are a valuable and powerful tool provided by Salesforce to the Admins as they are updated automatically in real-time whenever a record is accessed.

They are read-only fields and are calculated based on fields and expressions specified in the formula and the values present in those fields. It calculates the latest data when it is viewed or when any of the source fields changes. More interestingly, they can also be used in Reports or SOQL queries.

A formula field expression is composed of –

  • Fields of Records
  • Fields of Related Records
  • Formula Operators
  • Formula Functions

There are a few points to consider when we are creating formula fields like –

  • A formula field expression can contain only 3900 characters, including Spaces, return Characters & Comments.
  • You can’t delete a field that is being referenced by the formula field expression.
  • Long Text Area, Rich Text Area, Multi-Select Picklist and Encrypted type fields cannot be referenced in a formula field expression.
  • A field value cannot depend on another formula field that references it.

When creating a formula field, you have to specify the return type of the field, which is the type of value that a specific formula field will hold or, in other words, the type of the value that will be returned by the expression specified in the formula field. Following return, types are allowed for a formula field.

  • Checkbox
  • Currency
  • Date
  • Time
  • Datetime
  • Number
  • Percent

Creating a Formula Field

Now, let’s see how to create a formula field for an object. To explain the steps, let’s take a scenario to create a formula field on the Account object, named Annual Tax, to calculate Annual tax as 10% of the Annual Revenue.

To create a formula field for a specific object- 

  1. Go to the “Fields & Relationships” section of that specific object and click on the “New” button.
Using Formula Fields in Salesforce
  1. Choose “Formula” as Data Type and click on “Next”.
Using Formula Fields in Salesforce
  1. Choose “Formula Return Type”, provide a “Field Label” and Click on the “Next” button.
    (Like for current scenario we have chosen “Currency” as Return Type and “Annual Tax” as the field label)
Using Formula Fields in Salesforce
  1. Click on the “Simple Formula” tab, and make sure the “Select Field Type” combobox should point to the “Account” Object and click on the “Annual Revenue” field from the “Insert Field” combobox. [As required for current scenario]
Using Formula Fields in Salesforce
  1. Write the given formula to calculate the Annual Tax by using ‘(’, ‘*’, and ‘/’ operators from the Insert Operator combobox.
    ( AnnualRevenue * 10 ) / 100
  2. Click on the “Check Syntax” button to verify the expression and click on the “Next” button.
Using Formula Fields in Salesforce
  1. Choose the profile for which you want to make this field visible, and click on the “Next” button and click on the “Save” button.

Now when you see records of the Account Object, you can see the “Account Tax” is calculated as 10% of the Annual Revenue.

Using Formula Fields in Salesforce

Simple Formula vs Advanced Formula

You might have noticed the “Simple Formula” and “Advanced Formula” tab while creating the formula. Our current requirement is fulfilled by the “Simple Formula” itself, but you can use “Advanced Formula” as well. 

Now, let’s see what’s the difference between “Simple Formula” and “Advanced Formula”.

  • In Simple Formula, you can only use fields from the Current Object or Universal Objects like “User” and “Organization”. In contrast, in Advance Formula, you can use fields from Current Object and Related Objects (Parent) along with many Universal Objects.
Using Formula Fields in Salesforce
  • Formula Functions are not available in Simple Formula, but they are available in Advanced Formula.
Using Formula Fields in Salesforce
  • Logical Operators are not available in Simple Formula, but they are available in Advanced Formula.
Using Formula Fields in Salesforce

Now, let us see the various Formula Operators and Formula Functions that we can use in Formula Fields.

Formula Operators in Formula Fields

Following types of Formula Operators can be used in Formula Fields, and as discussed earlier, Simple Formula can only use Math Operators.

  • Math Operators – These operators are used to perform mathematical operations.
OperatorsDescriptionExampleResult
Add (+)To perform summation25 + 530
Subtract (-)To perform difference25 – 520
Multiply (*)To perform product25 * 5125
Divide (/)To perform division for the quotient25 / 212.5
Exponential (^)To perform the exponential operation25 ^ 2625
Parenthesis ‘(’ or ‘)’To override the order of operation(3+2) / 22.5
  • Logical Operators – These operators are used to perform comparison operations. All these operations either result in ‘True’ or ‘False’.
OperatorsDescriptionExampleResult
Equal (= and ==)It returns true when two values are equal.25 = = 25 True
Not Equal (!= and <>)It returns true when two values are not equal.25 <> 25False
Less Than (<)It returns true when the value on the left side is less than the value on the right side.25 < 25False
Greater Than (>)It returns true when the value on the left side is greater than the value on the right side.25 > 25False
Less Than or Equal(<=)It returns true when the value on the left side is less than or equal to the value on the right side.25 <= 25True
Greater Than or Equal(>=)It returns true when the value on the left side is greater than or equal to the value on the right side.25  >= 25True
AND (&&)It compares to Boolean Values (True or False) or expressions returning Boolean Values and returns true when both of the values are true otherwise false.T && T
T && F
F && T
F && F
True
False
False
False
OR (||)It compares to Boolean Values (True or False) or expressions returning Boolean Values and returns false when both of the values are false otherwise true.T || T
T || F
F || T
F || F
True
True
True
False
  • Text Operator – This operator is used to concatenate texts.
    • Concatenate [&] – For example ‘Hello’ & ’ World’ will result into ‘Hello World’

Formula Functions in Formula Fields

Following types of Formula Functions can be used in Formula Fields, and as discussed earlier, these are only available in Advanced Formulas.

Date & TimeTextMathLogicalAdvanced
ADDMONTHSBEGINSABSANDCURRENCYRATE
DATEBRCEILINGBLANKVALUE
DATETIMEVALUECASESAFEIDDISTANCECASE
DATEVALUECONTAINSEXPIF
DAYFINDFLOORISBLANK
HOURGETSESSIONIDLNISNULL
MILLISECONDHYPERLINKLOGISNUMBER
MINUTEIMAGEMAXNOT
MONTHINCLUDESMCEILINGNULLVALUE
NOWISPICKVALMFLOOROR
SECONDLEFTMIN
TIMENOWLENMOD
TIMEVALUELOWERROUND
TODAYLPADSQRT
WEEKDAYMID
YEARRIGHT
RPAD
SUBSTITUTE
TEXT
TRIM
UPPER
VALUE

We hope you enjoyed this blog! In the next one, we’ll be talking about the formula functions and their use cases and scenarios. until then you can take a dive into our other Salesforce blogs, See ya soon!! 🙂


Resources

Amit Kumar

Subscribe to our newsletter

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

Concretio Apps will use the information you provide on this form to be in touch with you and to provide updates and marketing.