• Default value formulas for a type of record can only reference fields for that type of record. However, formula fields and formulas for approvals or rules, such as workflow, validation, assignment, auto-response, or escalation, for a type of record can reference fields for that type of record as well as any records that are related through a lookup or master-detail relationship. For example, a formula for a validation rule on opportunities can reference merge fields for accounts and campaigns as well as opportunities, and a formula field on accounts can reference fields for cases.
• Formula fields that a user can see may reference fields that are hidden or read only using field-level security. If the formula field contains sensitive information, use field-level security to hide it.
• You can add activity formula fields to task and event page layouts. Note that a task-related formula field on an event page layout may not be useful. Likewise, event-related formula fields on task page layouts may not be useful.
• To determine if a record is a task or event, use the IsTask merge field. For example:
IF(IsTask, “This is a task”, “This is an event”)
• To reference the unique identifier for your Salesforce organization in a formula, insert the $Organization.Id merge field. This merge field can display anywhere formula fields can except in reports.
• Some merge fields display as radio buttons but function like picklist fields when referenced in a formula.
Use the values “Read,” “Edit,” and “None” in a formula when referencing:
◊ $UserRole.CaseAccessForAccountOwner
◊ $UserRole.OpportunityAccessForAccountOwner
◊ CaseAccessLevel (on Territory)
◊ OpportunityAccessLevel (on Territory)
Use the values “Read,” “Edit,” and “All” in a formula when referencing:
◊ AccountAccessLevel (on Territory)
• If you create a contacts formula field that references account merge fields, that field can be included in contact page layouts but should not be included in person accounts page layouts. The formula field will display a value of #Error on the person accounts page.
Restrictions
• The following limits apply to formula fields:
◊ Character limit—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.
Note: The maximum number of displayed characters after an evaluation of a formula expression is 1,300
characters.
◊ Save size limit—Formula fields cannot exceed 4,000 bytes when saved. The save size differs from the number of characters if you use multi-byte characters in your formula.
◊ Compile size limit—Formula fields cannot exceed 5,000 bytes when compiled. The compile size is the size of the formula (in bytes) including all of the fields, values, and formulas it references. There is no direct correlation between the compile size and the character limit. Some functions, such as TEXT, DATEVALUE, DATETIMEVALUE, and DATE significantly increase the compile size.
• Long text area, encrypted, and Description fields are not available for use in formulas.
• The value of a field cannot depend on another formula that references it.
• Fields referenced in formulas cannot be deleted. Remove the field from the formula before deleting it.
• Task Due Date is not available for use in formulas.
• Campaign statistic fields cannot be referenced in formulas for field updates, approval processes, workflow rules, or validation rules, but can be referenced in custom formula fields.
Working with Date and Date/Time Fields
• Dates and times are always calculated using the user’s time zone.
• Date and date/time fields cannot be used interchangeably. The name alone may not indicate if a field is a date or date/time.
For example, Created Date and Last Modified Date are date/time fields whereas Last Activity Date is a
date field. Use the DATEVALUE function to convert a date/time field into a date field.
Note: The Created Date and Last Modified Date fields display only the date, not the date and time.
• Use addition and subtraction operators with date or date/time fields to calculate duration. For example, subtract a date from another date to calculate the number of days between the two. Likewise, you can subtract the date/time from another date/time to get the number of days between the two in the form of a number. See NOW or TODAY for suggested use.
• Use addition and subtraction operators with numbers to return another date or date/time. For example, {!CreatedDate} + 5 calculates the date and time five days after a record’s created date. Note that the expression returns the same data type as the one given; a date field plus or minus a number returns a date, and a date/time field plus or minus a number returns a date/time.
• When calculating dates using fractions, Salesforce ignores any numbers beyond the decimal. For example:
TODAY() + 0.7 is the same as TODAY() + 0, which is today’s date TODAY() + 1.7 is the same asTODAY() + 1, which is tomorrow’s date TODAY() + (-1.8) is the same as TODAY() + (-1), which is yesterday’s date
• To calculate the value of two fractions first, group them within parentheses. For example:
TODAY() + 0.5 + 0.5 is the same as TODAY() + 0 + 0, which is today’s date TODAY() + (0.5+0.5) is the same as TODAY() + 1, which is tomorrow’s date
• Years cannot be zero and must be between -4713 and 9999.
Working with Text Fields
• Before using the HYPERLINK function, consider the differences between hyperlinks and custom links.
◊ Hyperlink formula fields are just like other custom fields that you can display in list views and reports.
◊ Custom links display on detail pages in a predefined section; hyperlink formula fields can display on a detail page wherever you specify.
◊ Using custom links, you can specify display properties such as window position and opening in a separate popup position; hyperlink formula fields open in a new browser window by default or you can specify a different target window or frame.
◊ Your formulas can reference custom links. Before deleting a custom link, make sure it is not referenced in a formula field.
◊ Hyperlink formula fields that contain relative URLs to Salesforce pages, such as /rpt/reportwizard.jsp, can be added to list views, reports, and related lists. However, use a complete URL, including the server name and https://, in your hyperlink formula before adding it to a search layout. Note that formula fields are not available in search result layouts.
• Before using the HYPERLINK function, consider these:
◊ Hyperlink formula fields open in a new browser window by default or you can specify a different target window or frame.
◊ Hyperlink formula fields that contain relative URLs to Salesforce pages can be added to list views and related lists.
However, use a complete URL, including the server name and https://, in your hyperlink formula before adding it to a search layout. Note that formula fields are not available in search result layouts.
• To insert text in your formula field, surround the text with quotation marks. For example, to display “CASE: 123,” use this formula “CASE: “& CaseNumber__c.
• Use the backslash (\) character before a quote or backslash to insert it as a literal value in your output. For example, “Trouble\\Case \”Ticket\”: ” in your formula displays Trouble\Case “Ticket”: on detail pages.
Working with Number Fields
• Use the decimal version of a percent when working with percent fields in formulas. For example, IF(Probability =1…) for 100% probability or IF(Probability =0.9…) for 90% probability.
• Reference auto-number fields as text fields in formulas.
• The output of your formula must be less than 19 digits.
• Formulas can contain a mix of numbers, percents, and currencies as in this example: AnnualRevenue /
NumberOfEmployees.
• 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.
Referencing Record Types in Formulas
Reference record types in formulas if you want different workflow rules, validation rules, and lookup filters to apply to different record types. For example, you can:
• Create a workflow rule on accounts that emails different teams depending on the account record type the user selects when creating the account.
• Create a validation rule on opportunities that allows only members of the North American sales team to save opportunities with the Domestic record type.
When possible, use RecordTypeId instead of RecordType.Name to reference a specific record type. While
RecordType.Name makes a formula more readable, you must update the formula if the name of the record type changes, whereas the ID of a record type never changes. Also, RecordType.Name requires a cross-object reference to the record type, while RecordTypeId does not. However, if you are deploying formulas across organizations (for example, between sandbox and production), use RecordType.Name because IDs are not the same across organizations.
Avoid using $RecordType in formulas, except in default value formulas. Instead, use the RecordType merge field (for example, Account.RecordType.Name) or the RecordTypeId field on the object.
Working with Picklists and Multi-Select Picklists
• You can use special picklist fields in your formulas, such as IsEscalated for cases and IsWon for opportunities.
• Picklist fields can only be used in the following functions:
◊ ISPICKVAL—Compares the value of a picklist to a single value.
◊ CASE—Compares the value of a picklist to multiple values.
◊ TEXT—Converts a picklist value into a text value so that you can work with the value in functions that support text value, such as CONTAINS. (Only available in formula fields, validation rules, and workflow field updates.)
• The TEXT function always returns picklist values in your organization’s master language, not the language of the current user.
• Multi-select picklist fields can only be used in the following functions:
◊ INCLUDES
◊ ISBLANK
◊ ISNULL
◊ ISCHANGED (Only in assignment rules, validation rules, workflow field updates, and workflow rules in which the evaluation criteria is set to Evaluate the rule when a record is: created, and every time it’s edited)
◊ PRIORVALUE (Only in assignment rules, validation rules, workflow field updates, and workflow rules in which the evaluation criteria is set to Evaluate the rule when a record is: created, and every time it’s edited).