How to build custom formula fields on Salesforce
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
Navigate to Object Manager
Create a New Custom Field
Configure Field Properties
Build Your Formula Expression
Amount * 0.1for 10% calculationIF(ISPICKVAL(Stage, "Closed Won"), Amount, 0)for conditional logicFirstName & " " & LastNamefor text concatenation
Validate Formula Syntax
- Matching parentheses and quotes
- Proper field API name references
- Correct function usage and parameters
Set Field-Level Security
Add to Page Layouts
Test and Verify Results
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.