Formula Fields in Salesforce

 Formula Fields


When you have a large amount of data in your org, Users need to understand the data without doing any manual calculations. For example, Let's say you need to calculate the percentage of a value, or perhaps find the day difference between two dates and much more. This is when the formula fields come in handy. Formula fields are an out-of-box salesforce feature that enables you to get more from your existing salesforce data.
It is a read-only field that we can create in a standard/custom object. Creating this field is similar to creating a normal salesforce field. The value of this field will be calculated based on the expression defined. 

Formulae results will be returned in 7 ways,
  1. Number
  2. Text
  3. Percentage
  4. Checkbox(Calculating boolean value)
  5. Date
  6. Date time
  7. Currency
Now let's have a small demo.

Here we will create a formula field on the opportunity object to find the difference between the Opportunity Created date and the Opportunity Closed Date.

STEP 1: Redirect to setup --> Object Manager --> Opportunity Object --> Fields and relationship --> Click on new 



STEP 2: Select formula --> Next




STEP 3: Enter the field label & field name and select Number as a formula return type(As we want the number of days difference between two dates). click next.



STEP 4: Enter 'Formula'

Depending on your requirements, the formula can have many functions and operators. We can even add a reference to related Objects fields.
Insert Operator and Insert field buttons are used to construct the formula. Once the formula is ready click on check syntax and make sure no error exists.



Once you are satisfied with the created formula, save it. 

Now you can see this newly created formula field on the opportunity object.

Formula fields come with a few limitations as well, 

1. Formula field can contain up to 3900 characters. Including comments, spaces, and return characters.
2. The Formula field can not exceed 4000 bytes when saved. and cannot exceed 15000 bytes when compiled.

Formula and logic are crucial in Salesforce, As they can be used in Validation rules, reports, and flows.



                                                                       

Comments