How to build custom formula fields on Salesforce

intermediate 8 min read Updated 2026-03-18
Quick Answer

Custom formula fields in Salesforce are read-only fields that automatically calculate values based on other fields, expressions, or functions. You create them through Setup > Object Manager by selecting your object, adding a new field, and choosing the Formula data type.

Prerequisites

  • Salesforce Admin or Developer access
  • Basic understanding of Salesforce objects and fields
  • Knowledge of formula syntax and functions
  • Familiarity with data types and field relationships

Step-by-Step Instructions

1

Navigate to Object Manager

Log into Salesforce and click the Setup gear icon in the top right corner. In the Setup menu, navigate to Platform Tools > Objects and Fields > Object Manager. Select the object where you want to create the formula field (e.g., Account, Contact, Opportunity).
Use the search box in Object Manager to quickly find your desired object if you have many custom objects.
2

Create a New Custom Field

On the object detail page, click Fields & Relationships from the left sidebar. Click the New button to start creating a new field. Select Formula from the data type options and click Next.
3

Configure Field Properties

Enter a Field Label (e.g., "Total Revenue") and Field Name (auto-populated). Add a Description to document the field's purpose. Select the appropriate Formula Return Type from the dropdown (Text, Number, Percent, Currency, Date, Date/Time, Checkbox, or Time).
Choose your return type carefully as it cannot be changed after saving the field.
4

Build Your Formula Expression

In the Formula text area, enter your formula expression using Salesforce formula syntax. Use the Insert Field button to reference other fields, and Insert Operator for mathematical or logical operators. Common examples:
  • Amount * 0.1 for 10% calculation
  • IF(ISPICKVAL(Stage, "Closed Won"), Amount, 0) for conditional logic
  • FirstName & " " & LastName for text concatenation
Use the Check Syntax button frequently to validate your formula as you build it.
5

Validate Formula Syntax

Click Check Syntax to verify your formula is correct. If there are errors, Salesforce will highlight the problematic areas and provide error messages. Common syntax requirements include:
  • Matching parentheses and quotes
  • Proper field API name references
  • Correct function usage and parameters
Fix any errors before proceeding.
Keep the Functions reference tab open to quickly look up function syntax and examples.
6

Set Field-Level Security

Click Next after validating your formula. On the Field-Level Security page, check the Visible and Read Only checkboxes for the appropriate profiles and permission sets. Formula fields are always read-only, but you can control visibility. Click Next to continue.
Remember that users need read access to referenced fields in your formula to see calculated results.
7

Add to Page Layouts

Select which page layouts should display your new formula field by checking the appropriate boxes. You can choose different sections within each layout. Click Save to create the field. The formula will immediately begin calculating for existing records.
You can always modify page layout placement later through the Page Layout editor.
8

Test and Verify Results

Navigate to a record of your object type to verify the formula field displays correctly. Check multiple records with different data scenarios to ensure the formula works as expected. If needed, return to Setup > Object Manager > your object > Fields & Relationships to edit the formula field and make adjustments.
Create test records with edge cases (null values, zero amounts) to thoroughly validate your formula logic.

Common Issues & Troubleshooting

Formula field shows #ERROR! or blank values

Check that all referenced fields have appropriate values and that your formula handles null values using functions like ISNULL() or BLANKVALUE(). Verify field API names are correct and users have read access to referenced fields.

Syntax error: 'Field does not exist' message

Ensure you're using the correct field API names, not field labels. For custom fields, API names end with __c. For lookup relationships, use RelationshipName__r.FieldName__c format to reference related object fields.

Formula field not updating when referenced fields change

Formula fields should update automatically when referenced fields change. If not updating, check if there are validation rules preventing saves, or if the formula references fields from different objects that might have security restrictions.

Cannot save formula due to field reference errors

Verify that cross-object references use the correct relationship syntax and that you're not trying to reference fields that are more than 10 relationship levels away. Check that lookup relationships exist and are properly configured between the objects.

Prices mentioned in this guide are pulled from current plan data and may change. Always verify on the official Salesforce website before purchasing.