A formula field is a field that automatically calculates its value from other fields, expressions, or values.

A formula can contain references to the values of fields, operators, functions, literal values, or other formulas.

Formula field values are calculated at the time of access; they are not reevaluated automatically when their referenced values change. As such, changes to formula field values do not fire triggers or declarative automation.

You can use any or all of the following elements to build a formula.

Literal Value
A text string or number you enter that is not calculated or changed. For example, if you have a value that’s always multiplied by 2% of an amount, your formula would contain the literal value of 2% of that amount:

ROUND((Amount*0.02), 2)

Field Reference
Reference the value of another custom or standard field using a merge field. The syntax for a merge field is field_name for a standard field or field_name__c for a custom field. The syntax for a merge field on a related object is object_name__r.field_name. Use the Insert Field button or the drop-down list to insert a merge field in your formula where necessary.

Function
A system-defined formula that can require input from you and returns a value or values. For example, TODAY() does not require input but returns the current date. The TEXT(value) function requires your percent, number, or currency input and returns text.

Operator
A symbol that specifies the type of calculation to perform or the order in which to do it. For example, the + symbol specifies two values should be added. The open and close parentheses specify which expressions you want evaluated first.

Comment
An annotation within a formula that begins with a forward slash followed by an asterisk (/*). and concludes with an asterisk followed by a forward slash (*/). For example,

/*This is a formula comment*/

Comments are ignored when processing a formula. You can also use comments to comment out sections of your formula when debugging and checking the syntax to locate errors in the formula.

Useful Documentation

history | excerpt history