---
schema_version: "1"
id: 5727617d8e43cc7999935db9c1bf1315141df348bef2bcb762339704ba4993cd
title: Elements of a Formula
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/platform/264-0-0/elements_of_a_formula.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.elements_of_a_formula.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 7b219b463f0c57ce1a8ba4751849ffe44fa73eeda3fc9932d10cf715418d758b
description: "Learn the elements you can combine to build a formula: literal values, field references, functions, operators, and comments. Understand what each element does and see an example of how to enter it."
products:
  - Salesforce Platform
  - Security
release: "264"
---
# Elements of a Formula

Learn the elements you can combine to build a formula: literal values, field references, functions, operators, and comments. Understand what each element does and see an example of how to enter it.

## How a Formula Is Built

Use any or all of these elements to build a formula. This example formula combines all elements to calculate 2% of an amount and round the result to two decimal places:

```
/* 2% of Amount, rounded to two decimal places */
ROUND( ( Amount*0.02 ), 2 )
```

This example uses:

- A function, `ROUND`, which returns a number rounded to a specified number of decimal places.
- A field reference, Amount.
- A literal value, 0.02.
- An operator, \*, which multiplies the value of the Amount field by the literal value 0.02.
- Another operator, parentheses ( ), which groups `Amount*0.02` as the first argument to `ROUND`.
- A second literal value, 2, which is the input that tells `ROUND` how many decimal places to return.
- A comment that describes the formula. Comments start with /\* and end with \*/. They’re ignored when the formula runs.

## Literal Value

A literal value is a number or text string that you enter directly in a formula. The value is used exactly as entered, without calculating or changing it.

- Enter a number directly, as plain digits without commas or currency symbols. Use the decimal form for percentages—for example, enter 0.02 for 2%. To represent $850,000, enter 850000, not 850,000 or $850000.
- Enter text by enclosing it in quotation marks. For example, this formula uses the IsWon checkbox on an opportunity and returns a text literal:
    
    ```
    IF( IsWon, "Won", "Not Won" )
    ```
    
    It returns the text “Won” when the opportunity is won. Otherwise it returns “Not Won”.
    
    To include a quotation mark or backslash within the text, precede it with a backslash. For an example, see [Tips for Working with Text in Formulas](https://help.salesforce.com/s/articleView?id=platform.tips_for_using_text_formula_fields.htm&release=264.0.0&type=5 "Get tips for working with text in formulas. Find guidance on using quotation marks to insert or concatenate text, escaping special characters with backslashes, and more.").

## Field Reference

A field reference (a merge field) uses the value of another standard or custom field in your formula. Use these syntax forms:

- Standard field: `field_name` (for example, Amount)
- Custom field: `field_name__C` (for example, Discount\_Percent\_\_c)
- Field on a related object (standard relationship): `RelationshipName.field_name` (for example, Account.Name)
- Field on a related object (custom relationship): `object_name__r.field_name` or `object_name__r.field_name__c` (for example, Position\_\_r.title\_\_c for a custom field)

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_click-264-0-0-production-enus/5f7d9219-b7b1-4552-8891-f1aba9b289fc/images/icon_note.png)

Note For fields on related objects, the relationship name is usually, but not always, the object name. For the full rules on relationship names, see [Merge Fields for Cross-Object Formulas](https://help.salesforce.com/s/articleView?id=platform.fields_merge_fields_cross_object.htm&release=264.0.0&type=5 "A Cross-object formula is a formula that spans two related objects and references merge fields on those objects.").

You can also reference a value from a custom metadata type. That’s configuration data stored separately from the record, not a field on the object. Use the `$CustomMetadata` global variable, and identify the type, the record, and the field. Use this syntax, replacing each token with your own API names:

```
$CustomMetadata.CustomMetadataTypeAPIName.RecordAPIName.FieldAPIName
```

In this example, `AnnualRevenue__mdt` is the custom metadata type, `Annual_Revenue` is the record’s API name, and Maximum\_Revenue\_\_c is the field:

```
$CustomMetadata.AnnualRevenue__mdt.Annual_Revenue.Maximum_Revenue__c
```

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_click-264-0-0-production-enus/5f7d9219-b7b1-4552-8891-f1aba9b289fc/images/icon_note.png)

Note Referencing custom metadata in formula fields is available in Enterprise, Performance, Unlimited, and Developer Editions.

To insert a merge field without typing it, use the **Insert Field** button or the dropdown list.

## Function

A function is a system-defined formula that returns a value or values, and can require input from you. Salesforce provides many functions. These functions show how input works:

- `TODAY()` requires no input and returns the current date.
- `TEXT(` value `)` requires input, such as a percent, number, or currency value, and returns text.
    
    For example, `TEXT(ExpectedRevenue)` converts a currency amount such as $200,000 to the text 200000, without the dollar sign or comma.

For a complete list of functions, see [Formula Operators and Functions by Context](https://help.salesforce.com/s/articleView?id=platform.customize_functions.htm&release=264.0.0&type=5 "Use these operators and functions when building formulas. All functions are available everywhere that you can include a formula, such as formula fields, validation rules, approval processes, and workflow rules, unless otherwise specified.").

## Operator

An operator is a symbol that specifies the type of calculation to perform, or the order in which to perform calculations. For example:

- The + symbol adds two values.
- Parentheses ( ) specify which expressions to evaluate first.

Comparison operators test whether a condition is true. They include:

- < (less than)
- \> (greater than)
- <= (less than or equal to)
- \>= (greater than or equal to)
- \= (equal to)
- <> (not equal to)

This example uses < to compare a currency field with a number:

```
AnnualRevenue < 850000
```

`AnnualRevenue < 850000` is `TRUE` when an account’s annual revenue is under $850,000.

For the complete list of operators, see [Formula Operators and Functions by Context](https://help.salesforce.com/s/articleView?id=platform.customize_functions.htm&release=264.0.0&type=5 "Use these operators and functions when building formulas. All functions are available everywhere that you can include a formula, such as formula fields, validation rules, approval processes, and workflow rules, unless otherwise specified.").

## Comment

A comment is an annotation within a formula. It begins with a forward slash and asterisk (`/*`) and ends with an asterisk and forward slash (`*/`), as shown in this example:

```
/*This is a formula comment*/
```

Comments document specific parts of a formula for anyone viewing its definition. Salesforce ignores comments when it processes a formula.

This example uses comments to document each part of a multi-part formula. The field names, record type name, and picklist text are for illustration. Replace them with values from your org.

```
AND( 
/*competitor field is required, check to see if field is empty */
LEN( Competitor__c ) = 0, 
/* rule only enforced for New Business record types */
RecordType.Name = "New Business",
/* checking for any closed status, allows for additional closed picklist values in the future */
CONTAINS( TEXT( StageName ), "Closed" ) 
)
```

You can also comment out sections of a formula to debug and check the syntax while locating errors.

Keep these considerations in mind:

- Nesting comments causes a syntax error. For example, you can’t save a formula that contains this string:
    
    ```
    /* /* comment */ */
    ```
- Commenting out an entire formula causes a syntax error.
- Comments count against the character and byte size limits in formulas.

#### See Also

- [Find Examples of Advanced Formulas](https://help.salesforce.com/s/articleView?id=platform.useful_advanced_formulas.htm&release=264.0.0&type=5 "Review sample formulas for sales, service, financial, employee-services, and integration scenarios. Examples cover commissions and discounts, cross-object references, date and time calculations, image links, data completeness, and more. Adapt the formulas to your fields and business requirements.")