Build a Formula Field
Your custom formula fields require special attributes.
Required Editions
| Available in: both Salesforce Classic and Lightning Experience |
| Available in: All Editions |
| User Permissions Needed | |
|---|---|
| To view formula field details: | View Setup and Configuration |
| To create, change, or delete formula fields: | Customize Application |
Note The Getting Started with Formulas (Salesforce
Classic) help video includes a live demo of these steps.
- Begin building a formula field the same way you create a custom field. See Create Custom Fields.
- Select the data type for the formula. Choose the appropriate data type for your formula based on the output of your calculation. See Formula Data Types.
- Choose the number of decimal places for currency, number, or percent data types. This setting is ignored for currency fields in multicurrency organizations. Instead, the Decimal Places for your currency setting apply. Salesforce uses the round half up tie-breaking rule for numbers in formula fields. For example, 12.345 becomes 12.35 and −12.345 becomes −12.35.
- Click Next.
-
Build your formula. Formula fields can contain up to 3,900 characters, including
spaces, return characters, and comments. If your formula requires more characters,
create separate formula fields and reference them in another formula field. The
maximum number of displayed characters after an evaluation of a formula expression is
1,300
- If you are building a formula in the Advanced Formula tab or for approvals or rules, such as workflow, validation, assignment, auto-response, or escalation, click Insert Field, choose a field, and click Insert. To create a basic formula that passes specific Salesforce data, select the Simple Formula tab, choose the field type in the Select Field Type drop-down list, and choose one of the fields listed in the Insert Field drop-down list. Build cross-object formulas to span to related objects and reference merge fields on those objects.
- To insert an operator, choose the appropriate operator icon from the Insert Operator drop-down list.
- Optionally, click the Advanced Formula tab to use functions and view other operators and merge fields. Functions are prebuilt formulas that you can customize with your input parameters.
- To insert a function, double-click its name in the list, or select it and click Insert Selected Function. To filter the list of functions, choose a category from the Functions drop-down list. Select a function and click Help on this function to view a description and examples of formulas using that function.
-
Consider adding comments to your formula, especially if it is complicated.
Comments must begin with a forward slash followed by an asterisk (
/*), and conclude with an asterisk followed by a forward slash (*/).Comments are useful for explaining specific parts of a formula to anyone viewing the formula definition. For example:
AND( /*competitor field is required, check to see if field is empty */ LEN(Competitor__c) = 0, /* rule only enforced for ABCD record types */ RecordType.Name = "ABCD Value", /* checking for any closed status, allows for additional closed picklist values in the future */ CONTAINS(TEXT(StageName), "Closed") )
- To check your formula for errors, click Check Syntax.
- Optionally, enter a description of the formula in the Description box.
- If your formula references any number, currency, or percent fields, choose an option for handling blank fields. To give any blank fields a zero value, choose Treat blank fields as zeros. To leave these fields blank, choose Treat blank fields as blanks.
- Click Next.
- Set the field-level security to determine whether the field should be visible for specific profiles, and click Next.
- Choose the page layouts that should display the field. The field is added as the last field in the first two-column section on the page layout. For user custom fields, the field is automatically added to the bottom of the user detail page.
- Click Save to finish or Save & New to create more custom fields.
Note Because formula fields are automatically calculated, they are
read-only on record detail pages and do not update last modified date fields. Formula
fields are not visible on edit pages.
In account formulas, all business account fields are available as merge fields. However, account fields exclusive to person accounts such as Birthdate and Email are not available.
- What Is a Cross-Object Formula?
A Cross-object formula is a formula that spans two related objects and references merge fields on those objects. A cross-object formula can reference merge fields from a master (“parent”) object if an object is on the detail side of a master-detail relationship. A cross-object formula also works with lookup relationships.
Did this article solve your issue?
Let us know so we can improve!

