Salesforce Useful Formula Fields
Salesforce Useful Formula Fields
Summary Review examples of formula fields for various types of apps that you can use and modify for your own
purposes.
Review examples of formula
fields for various types of This document contains custom formula samples for the following topics. For details about using the
functions included in these samples, see Formula Operators and Functions by Context on page 32.
apps that you can use and
modify for your own
purposes. Sample Account Management Formulas
Use these formulas to manage account details.
For details about using the functions included in these samples, see Formula Operators and Functions by
Context on page 32.
Account Rating
This formula evaluates Annual Revenue, Billing Country, and Type, and assigns a value
of “Hot,” “Warm,” or “Cold.”
IF (AND (AnnualRevenue > 10000000,
CONTAINS (CASE (BillingCountry, "United States", "US", "America", "US",
"USA", "US", "NA"), "US")),
IF(ISPICKVAL(Type, "Manufacturing Partner"), "Hot",
IF(OR (ISPICKVAL (Type, "Channel Partner/Reseller"),
ISPICKVAL(Type, "Installation Partner")), "Warm", "Cold")),
"Cold")
In addition, you can reference this Account Rating formula field from the contact object using cross-object
formulas.
Account.Account_Rating__c
Account Region
This formula returns a text value of “North,” “South,” “East,” “West,” or “Central” based on the Billing
State/Province of the account.
IF(ISBLANK(BillingState), "None",
IF(CONTAINS("AK:AZ:CA:HA:NV:NM:OR:UT:WA", BillingState), "West",
IF(CONTAINS("CO:ID:MT:KS:OK:TX:WY", BillingState), "Central",
IF(CONTAINS("CT:ME:MA:NH:NY:PA:RI:VT", BillingState), "East",
IF(CONTAINS("AL:AR:DC:DE:FL:GA:KY:LA:MD:MS:NC:NJ:SC:TN:VA:WV",
BillingState), "South",
IF(CONTAINS("IL:IN:IA:MI:MN:MO:NE:ND:OH:SD:WI", BillingState), "North",
"Other"))))))
Contract Aging
This formula calculates the number of days since a contract with an account was activated. If the contract
Status isn’t “Activated,” this field is blank.
IF(ISPICKVAL(Contract_Status__c, "Activated"),
NOW() - Contract_Activated_Date__c, null)
MarketWatch™ Search
This formula creates a link to an account's ticker symbol on the Marketwatch.com website.
HYPERLINK(
"http://www.marketwatch.com/investing/stock/"&TickerSymbol,
"Marketwatch")
2
Examples of Advanced Formula Fields Sample Case Management Formulas
Google™ Search
This formula creates a link to a Google search site using the Account Name.
HYPERLINK(
"http://www.google.com/#q="&Name,
"Google")
Yahoo!™ Search
This formula creates a link to a Yahoo! search site using the Account Name.
HYPERLINK(
"http://search.yahoo.com/search?p="&Name,
"Yahoo Search")
Autodial
This formula creates a linkable phone number field that automatically dials the phone number when
clicked. In this example, replace "servername" and "call" with the name of your dialing tool
and the command it uses to dial. The merge field, Id, inserts the identifier for the contact, lead, or account
record. The first Phone merge field tells the dialing tool what number to call and the last Phone merge
field uses the value of the Phone field as the linkable text the user clicks to dial.
HYPERLINK("http://servername/call?id=" & Id & "&phone=" &
Phone, Phone)
3
Examples of Advanced Formula Fields Sample Commission Calculations Formulas
Case Categorization
This formula displays a text value of “RED,” “YELLOW,” or “GREEN,” depending on the value of a case age
custom text field.
IF(DaysOpen__c > 20, "RED",
IF(DaysOpen__c > 10, "YELLOW",
"GREEN") )
Suggested Offers
This formula suggests a product based on the support history for a computer reseller. When the Problem
custom field matches a field, the formula field returns a suggestion.
CASE(Problem__c,
"Memory", "Suggest new memory cards", "Hard Drive failure", "Suggest
new hard drive with tape backup",
"")
4
Examples of Advanced Formula Fields Sample Contact Management Formulas
This example calculates the commission amount for any opportunity that has a “Closed Won” stage. The
value of this field is the amount times 0.02 for any closed or won opportunity. Open or lost opportunities
have a zero commission value.
Commission Maximum
This formula determines what commission to log for an asset based on which is greater: the user's
commission percentage of the price, the price times the discount percent stored for the account or 100
dollars. This example assumes you have two custom percent fields on users and assets.
MAX($User.Commission_Percent__c * Price,
Price * Account_Discount__c, 100)
5
Examples of Advanced Formula Fields Sample Contact Management Formulas
If the account website URL is long, use the HYPERLINK function to display a label such as “Click Here”
instead of the URL. For example:
IF(Account.Website="", "",
IF(
OR(LEFT(Account.Website, 7) = "http://",LEFT(Account.Website, 8) =
"https://"),
HYPERLINK( Account.Website , "Click Here" ),
HYPERLINK( "https://" & Account.Website , "Click Here" )
)
)
This formula also adds the necessary "https://" before a URL if “http://” or “https://” wasn’t previously
included in the URL field.
5. Click Save.
Remember to add this link to the Contact page layout in order for it to show up.
6
Examples of Advanced Formula Fields Sample Contact Management Formulas
Contact Priority
This formula assesses the importance of a contact based on the account rating and the contact's title. If
the account rating is Hot or the title starts with Executive, then the priority is high (P1). If the account
rating is Warm or the title starts with VP then the priority is medium (P2), and if the account rating is
Cold then the priority is low (P3).
"P3")
)
)
Contact Yahoo! ID
This formula displays a clickable Yahoo! Messenger icon indicating if the person is logged on to the service.
Users can click the icon to launch a Yahoo! Messenger conversation with the person. This example uses
a custom text field called Yahoo Name on contacts where you can store the contact's Yahoo! Messenger
ID.
HYPERLINK("ymsgr:sendIM?" & Yahoo_Name__c,
IMAGE("https://opi.yahoo.com/online?u=" &
Yahoo_Name__c &
"&m;=g&t;=0", "Yahoo"))
7
Examples of Advanced Formula Fields Sample Data Categorization Formulas
8
Examples of Advanced Formula Fields Using Date, Date/Time, and Time Values in Formulas
Product Categorization
This formula checks the content of a custom text field named Product_Type and returns Parts
for any product with the word “part” in it. Otherwise, it returns Service. The values are case-sensitive,
so if a Product_Type field contains the text “Part” or “PART,” this formula returns Services.
IF(CONTAINS(Product_Type__c, "part"), "Parts", "Service")
9
Examples of Advanced Formula Fields Using Date, Date/Time, and Time Values in Formulas
Keep in mind that complex date functions tend to compile to a larger size than text or number formula
functions, so you might run into issues with formula compile size. See Tips for Reducing Formula Size for
help with this problem.
10
Examples of Advanced Formula Fields Using Date, Date/Time, and Time Values in Formulas
HOUR(), MINUTE(), SECONDS(), and MILLISECONDS() functions are valid parameters for
TIMEVALUE().
Use the TIMEVALUE(value) function to return the Time value of a Date/Time type, text, merge field
or expression. For example, extract the time from a ClosedDate Date/Time value with
TIMEVALUE(ClosedDate).
This returns the date in the format “YYYY-MM-DD” rather than in the locale-dependent format. You can
change the format by extracting the day, month, and year from the date first and then recombining them
in the format you want. For example:
"Today's date is " & TEXT( MONTH( date ) ) & "/" & TEXT( DAY( date )
) & "/" & TEXT( YEAR( date ) ) )
You can also convert text to a Date so you can use the string value with your other Date fields and formulas.
You’ll want your text to be formatted as “YYYY-MM-DD”. Use this formula to return the Date value:
DATEVALUE( "YYYY-MM-DD" )
In this formula, NOW() is offset to GMT. Normally, NOW() would be converted to the user’s time zone
when viewed, but because it’s been converted to text, the conversion won’t happen. So if you execute
this formula on August 1st at 5:00 PM in San Francisco time (GMT-7), the result is “The current date and
time is 2013–08–02 00:00:00Z”.
When you convert a Date/Time to text, a “Z” is included at the end to indicate GMT. TEXT( date/time
) returns “Z” if the field is blank. So if the Date/Time value you’re working with might be blank, check for
this before converting to text:
IF(
ISBLANK( date/time ),
"",
TEXT( date/time )
)
To convert a string to a Date/Time value, use DATETIMEVALUE() passing in a string in the format
“YYYY-MM-DD HH:MM:SS”. This method returns the Date/Time value in GMT.
11
Examples of Advanced Formula Fields Using Date, Date/Time, and Time Values in Formulas
TIMEVALUE("17:30:45.125")
In the calculation, NOW() is 2013–08–01 19:00:00Z, and then subtracted from 2013–08–02 07:00:00Z,
to return the expected result of 0.5 (12 hours).
Suppose that instead of NOW(), the formula converts the string “2013–08–01 12:00:00” to a Date/Time
value:
Date_Time_c - DATETIMEVALUE( "2013-08-01 12:00:00" )
12
Examples of Advanced Formula Fields Using Date, Date/Time, and Time Values in Formulas
The formula for shifted quarters is similar, but shifts the month of the date by the number of months
between January and the first quarter of the fiscal year. The following example shows how to find a date’s
quarter if Q1 starts in February instead of January.
ITo check whether a date is in the current quarter, add a check to compare the date’s year and quarter
with TODAY()’s year and quarter.
AND(
CEILING( MONTH( date ) / 3 ) = CEILING( MONTH( TODAY() ) / 3 ),
YEAR( date ) = YEAR( TODAY() )
)
13
Examples of Advanced Formula Fields Using Date, Date/Time, and Time Values in Formulas
To find the current week number, determine the days to date in the current year and divide that value by
7. The IF() statement ensures that the week number the formula returns doesn’t exceed 52. So if the
given date is December 31 of the given year, the formula returns 52, even though it’s more than 52 weeks
after the first week of January.
If your organization uses multiple languages, you can replace the names of the month with a custom
label:
CASE(
MONTH( date ),
1, $Label.Month_of_Year_1,
2, $Label.Month_of_Year_2,
14
Examples of Advanced Formula Fields Using Date, Date/Time, and Time Values in Formulas
3, $Label.Month_of_Year_3,
4, $Label.Month_of_Year_4,
5, $Label.Month_of_Year_5,
6, $Label.Month_of_Year_6,
7, $Label.Month_of_Year_7,
8, $Label.Month_of_Year_8,
9, $Label.Month_of_Year_9,
10, $Label.Month_of_Year_10,
11, $Label.Month_of_Year_11,
$Label.Month_of_Year_12
)
This formula only works for dates after 01/07/1900. If you work with older dates, use the same process
with any Sunday before to your earliest date, for example, 01/05/1800.
You can adjust this formula if your week starts on a different day. For example, if your week starts on
Monday, you can use January 8, 1900 in your condition. The new formula looks like this:
CASE(
MOD( date - DATE( 1900, 1, 8 ), 7 ),
0, "Monday",
1, "Tuesday",
2, "Wednesday",
3, "Thursday",
4, "Friday",
5, "Saturday",
"Sunday"
)
To get the formula for the name of the month, if your organization uses multiple languages, you can
replace the names of the day of the week with a variable like $Label.Day_of_Week_1, and so on.
15
Examples of Advanced Formula Fields Using Date, Date/Time, and Time Values in Formulas
You can substitute either a constant or another field in for the day_of_week value based on your
needs.
In this formula, date_1 is the more recent date and date_2 is the earlier date. If your work week runs
shorter or longer than five days, replace all fives in the formula with the length of your week.
16
Examples of Advanced Formula Fields Using Date, Date/Time, and Time Values in Formulas
For example, if you want to add 4 months to a date, use this formula.
ADDMONTHS(date + 4)
If the date that you provide is the last of any month, this formula returns the last day of the resulting
month.
To add a certain number of years to a date, use this formula.
ADDMONTHS(date, 12*num_years)
If the date that you provide is February 29, and the resulting year isn’t a leap year, the formula returns the
date as February 28. In this scenario, if you want the resulting date as March 1, use this formula.
This formula finds the day of the week of the date field value. If the date is a Wednesday, Thursday, or
Friday, the formula adds five calendar days, two weekend days, three weekdays, to the date to account
for the weekend. If date is a Saturday, you need four additional calendar days. For any other day of the
week Sunday Tuesday, simply add three days. You can easily modify this formula to add more or fewer
business days. The tip for getting the day of the week is useful to use to adjust this formula.
17
Examples of Advanced Formula Fields Using Date, Date/Time, and Time Values in Formulas
For minutes:
For seconds:
To return the time as a string in “HH:MM:SS A/PM” format, use the following formula:
IF(
OR(
VALUE( MID( TEXT( date/time - TZoffset ), 12, 2 ) ) = 0,
VALUE( MID( TEXT( date/time - TZoffset ), 12, 2 ) ) = 12
),
"12",
TEXT( VALUE( MID( TEXT( date/time - TZoffset ), 12, 2 ) )
-
IF(
VALUE( MID( TEXT( date/time - TZoffset ), 12, 2 ) ) < 12,
0,
12
)
)
18
Examples of Advanced Formula Fields Using Date, Date/Time, and Time Values in Formulas
)
& ":" &
MID( TEXT( date/time - TZoffset ), 15, 2 )
& ":" &
MID( TEXT( date/time - TZoffset ), 18, 2 )
& " " &
IF(
VALUE( MID( TEXT( date/time - TZoffset ), 12, 2 ) ) < 12,
"AM",
"PM"
)
When working with time in formula fields, always consider the time difference between your organization
and GMT. See A Note About Date/Time and Time Zones on page 12 for more information about the time
zone offset used in this formula.
19
Examples of Advanced Formula Fields Sample Discounting Formulas
You can change the eights in the formula to account for a longer or shorter work day. If you live in a
different time zone or your work day doesn’t start at 9:00 AM, change the reference time to the start of
your work day in GMT. See A Note About Date/Time and Time Zones for more information.
ROUND(Amount-Amount* Discount_Percent__c,2)
20
Examples of Advanced Formula Fields Sample Employee Services Formulas
Bonus Calculation
This example determines an employee's bonus amount based on the smallest of two amounts: the
employee's gross income times a bonus percent or an equally divided amount of the company's
performance amount among all employees. It assumes you have a custom number field for Number
of Employees, a custom percent field for Bonus Percent, and currency custom fields for the
employee's Gross and company's Performance.
MIN(Gross__c * Bonus_Percent__c,
Performance__c / Number_of_Employees__c)
Employee 401K
This example formula determines which amount to provide in employee 401K matching based on a
matching program of half of the employee's contribution or $250, whichever is less. It assumes you have
a custom currency field for Contribution.
MIN(250, Contribution__c /2)
21
Examples of Advanced Formula Fields Sample Expense Tracking Formulas
Expense Identifier
This formula displays the text Expense- followed by trip name and the expense number. This field a
text formula field that uses an expense number custom field.
"Expense-" &
Trip_Name__c & "-" & ExpenseNum__c
Mileage Calculation
This formula calculates mileage expenses for visiting a customer site at 35 cents a mile.
Miles_Driven__c * 0.35
Compound Interest
This formula calculates the interest that you have after T years, compounded M times per year.
Principal__c * ( 1 + Rate__c / M ) ^ ( T * M) )
Consultant Cost
This formula calculates the number of consulting days times 1200 given that this formula field is a currency
data type and consulting charges a rate of $1200 per day. Consulting Days is a custom field.
Consulting_Days__c *
1200
22
Examples of Advanced Formula Fields Sample Image Link Formulas
Gross Margin
This formula provides a simple calculation of gross margin. In this formula example, Total Sales
and Cost of Goods Sold are custom currency fields.
Total_Sales__c - Cost_of_Goods_Sold__c
Payment Status
This formula determines if the payment due date is past and the payment status is “UNPAID.” If so, it
returns the text “PAYMENT OVERDUE” and if not, it leaves the field blank. This example uses a custom date
field called Payment Due Date and a text custom field called Payment Status on contracts.
IF(
AND(Payment_Due_Date__c < TODAY(),
ISPICKVAL(Payment_Status__c, "UNPAID")),
"PAYMENT OVERDUE",
null )
23
Examples of Advanced Formula Fields Sample Image Link Formulas
24
Examples of Advanced Formula Fields Sample Integration Link Formulas
25
Examples of Advanced Formula Fields Sample Lead Management Formulas
Session identifiers from different contexts, and the sessions themselves, are different. When you
transition between contexts, the new session replaces the previous one, and the previous session
is no longer valid. The session ID also changes at this time.
Normally Salesforce transparently handles session hand-off between contexts, but if you’re passing
the session ID around yourself, you must reaccess $Api.Session_ID or GETSESSIONID()
from the new context to ensure a valid session ID.
Not all sessions are created equal. In particular, sessions obtained in a Lightning Experience context
have reduced privileges, and don't have API access. You can't use these session IDs to make API
calls. {!$Api.Session_ID} isn’t generated for guest users.
26
Examples of Advanced Formula Fields Sample Metric Formulas
Lead Numbering
This formula returns a number value for the text value in the auto-number field Lead Number, which
can be useful if you want to use the Lead Number field in a calculation, such as round-robin or other
routing purposes. Auto-number fields are text fields and must be converted to a number for numeric
calculations.
VALUE(Lead_Number__c)
This formula is for a custom formula field named Round_Robin_ID that assigns each lead a value of 0, 1,
or 2. This formula uses a custom auto-number field called Lead Number that assigns each lead a
unique number starting with 1. The MOD function divides the lead number by the number of lead queues
available (three in this example) and returns a remainder of 0, 1, or 2. Use the value of this formula field
in your lead assignment rules to assign lead records to different queues. For example:
• Round_Robin_ID = 0 is assigned to Queue A
• Round_Robin_ID = 1 is assigned to Queue B
• Round_Robin_ID = 2 is assigned to Queue C
27
Examples of Advanced Formula Fields Sample Opportunity Management Formulas
Temperature Conversion
This formula converts Celsius degrees to Fahrenheit.
1.8 * degrees_celsius__c + 32
Maintenance Calculation
This formula calculates maintenance fees as 20% of license fees per year. Maintenance Years is a
custom field on opportunities.
Amount * Maint_Years__c * 0.2
Monthly Value
This formula divides total yearly value by 12 months.
Total_value__c / 12
28
Examples of Advanced Formula Fields Sample Opportunity Management Formulas
Amount + Maint_Amount__c +
Services_Amount__c
Opportunity Categorization
This formula uses conditional logic to populate an Opportunity category text field, based on
the value of the Amount standard field. Opportunities with amounts less than $1500 are “Category 1,”
opportunities with amounts between $1500 and $10,000 are “Category 2,” and the rest are “Category 3.”
This example uses nested IF statements.
IF(Amount < 1500, "Category 1", IF(Amount > 10000, "Category 3",
"Category 2"))
29
Examples of Advanced Formula Fields Sample Opportunity Management Formulas
Consulting_Days__c * 1200
Sales Coach
This formula creates a hyperlink that opens a stage-specific document stored in the Documents tab. It
uses the previously defined custom formula field that identifies a document based on opportunity Stage.
See Stage-Based Sales Document Selection on page 30.
HYPERLINK("/servlet/servlet.FileDownload?file=" & Relevant_Document__c,
"View Document in New Window")
30
Examples of Advanced Formula Fields Sample Pricing Formulas
Total Amount
This formula calculates a total amount based on unit pricing and total units.
Unit_price__c * Total_units__c
User Pricing
This formula calculates a price per user license.
Total_license_rev__c / Number_user_licenses__c
Lead Scoring
This formula scores leads, providing a higher score for phone calls than website requests.
CASE(LeadSource, "Phone", 2, "Web", 1, 0)
31
Examples of Advanced Formula Fields Formula Operators and Functions by Context
Math Operators
Operator Description
+ (Add) Calculates the sum of two values.
() (Open Parenthesis Specifies that the expressions within the open parenthesis and close parenthesis
and Closed are evaluated first. All other expressions are evaluated using standard operator
Parenthesis) precedence.
32
Examples of Advanced Formula Fields Formula Operators and Functions by Context
Logical Operators
Operator Description
= and == (Equal) Evaluates if two values are equivalent. The = and == operators are
interchangeable.
< (Less Than) Evaluates if a value is less than the value that follows this symbol.
> (Greater Than) Evaluates if a value is greater than the value that follows this symbol.
<= (Less Than or Evaluates if a value is less than or equal to the value that follows this symbol.
Equal)
>= (Greater Than or Evaluates if a value is greater than or equal to the value that follows this symbol.
Equal)
&& (And) Evaluates if two values or expressions are both true. Use this operator as an
alternative to the logical function AND.
|| (Or) Evaluates if at least one of multiple values or expressions is true. Use this operator
as an alternative to the logical function OR.
Text Operators
Operator Description
& and + Connects two or more strings.
(Concatenate)
DATE Returns a date value from the year, month, and day values that you enter.
Salesforce displays an error on the detail page if the value of the DATE function
in a formula field is an invalid date, such as February 29 in a non-leap year.
DAY Returns a day of the month in the form of a number from 1 through 31.
33
Examples of Advanced Formula Fields Formula Operators and Functions by Context
Function Description
DAYOFYEAR Returns the day of the calendar year in the form of a number from 1 through
366.
FORMATDURATION Formats the number of seconds with optional days, or the difference between
times or dateTimes as HH:MI:SS.
HOUR Returns the local time hour value without the date in the form of a number from
1 through 24.
ISOWEEK Returns the ISO 8601-week number, from 1 through 53, for the given date,
ensuring that the first week starts on a Monday.
ISOYEAR Returns the ISO 8601 week-numbering year in 4 digits for the given date, ensuring
that the first day is a Monday.
MILLISECOND Returns a milliseconds value in the form of a number from 0 through 999.
MINUTE Returns a minute value in the form of a number from 0 through 60.
MONTH Returns the month, a number from 1 (January) through 12 (December) in number
format of a given date.
SECOND Returns a seconds value in the form of a number from 0 through 60.
TIMENOW Returns a time value in GMT representing the current moment. Use this function
instead of the NOW function if you only want to track time, without a date.
TIMEVALUE Returns the time value without the date, such as business hours.
UNIXTIMESTAMP Returns the number of seconds since 1 Jan 1970 for the given date, or number
of seconds in the day for a time.
WEEKDAY Returns the day of the week for the given date, using 1 for Sunday, 2 for Monday,
through 7 for Saturday.
Logical Functions
Function Description
AND Returns a TRUE response if all values are true, and returns a FALSE response if
one or more values are false.
CASE Checks a given expression against a series of values. If the expression is equal to
a value in the series, returns the corresponding result. If it isn’t equal to a value
in the series, returns the else_result.
34
Examples of Advanced Formula Fields Formula Operators and Functions by Context
Function Description
IF Determines if expressions are true or false. Returns a given value if true and
another value if false.
ISBLANK Determines if an expression has a value, and returns TRUE if it doesn’t. If it contains
a value, returns FALSE.
ISCLONE Checks if the record is a clone of another record, and returns TRUE if one item is
a clone. Otherwise, returns FALSE.
ISNEW Checks if the formula is running during the creation of a new record, and returns
TRUE if it is. If an existing record is being updated, returns FALSE.
ISNULL Determines if an expression is null (blank), and returns TRUE if it is. If it contains
a value, returns FALSE.
You must use ISBLANK instead of ISNULL in new formulas. ISBLANK has the same
functionality as ISNULL, but also supports text fields. Salesforce continues to
support ISNULL, so you don’t change any existing formulas.
ISNUMBER Determines if a text value is a number, and returns TRUE if it is. Otherwise, returns
FALSE.
OR Determines if expressions are true or false. Returns TRUE if any expression is true,
and returns FALSE if all expressions are false.
Math Functions
Function Description
ABS Calculates the absolute value of a number. The absolute value of a number is
the number without its positive or negative sign.
ACOS Returns the arc cosign of the number in radians, if the given number is from -1
through 1. Otherwise, returns NULL.
ASIN Returns the arc sine of the number in radians, if the given number is from -1
through 1. Otherwise, returns NULL.
35
Examples of Advanced Formula Fields Formula Operators and Functions by Context
Function Description
CEILING Rounds a number up to the nearest integer, away from zero if negative.
CHR Returns a string with the first character’s code point as the given number.
COS Returns the cosine of the number in radians, if the given number is from -1
through 1. Otherwise, returns NULL.
EXP Returns a value for e raised to the power of a number that you specify.
FLOOR Returns a number rounded down to the nearest integer, towards zero if negative.
FROMUNIXTIME Returns the datetime that represents the given number as the seconds elapsed
since 1 Jan 1970.
GEOLOCATION Returns a geolocation based on the provided latitude and longitude. Must be
used with the DISTANCE function.
MFLOOR Rounds a number down to the nearest integer, away from zero if negative.
PI Returns pi.
ROUND Returns the nearest number to a number that you specify, constraining the new
number by a specified number of digits.
SIN Returns the sine of the number, where the number is given in radians.
TAN Returns the tangent of the number, where the number is given in radians.
Text Functions
Function Description
ASCII Returns the first character’s code point from the given string as a number.
36
Examples of Advanced Formula Fields Formula Operators and Functions by Context
Function Description
BEGINS Determines if text begins with specific characters. Returns TRUE if it does, and
returns FALSE if it doesn't.
CONTAINS Compares two arguments of text, and returns TRUE if the first argument contains
the second argument. If not, returns FALSE.
FIND Returns the position of a string within a string of text represented as a number.
HTMLENCODE Encodes text and merge field values for use in HTML by replacing characters
that are reserved in HTML, such as the greater-than sign (>), with HTML entity
equivalents, such as >.
HYPERLINK Creates a link to a URL specified that is linkable from the text specified.
IMAGE Inserts an image with alternate text and height and width specifications.
INCLUDES Determines if any value selected in a multi-select picklist field equals a text literal
that you specify.
INITCAP Returns the text as lowercase with the first character of each word in uppercase.
ISPICKVAL Determines if the value of a picklist field is equal to a text literal that you specify.
JSENCODE Encodes text and merge field values for use in JavaScript by inserting escape
characters, such as a backslash (\), before unsafe JavaScript characters, such as
the apostrophe (').
JSINHTMLENCOD Encodes text and merge field values for use in JavaScript inside HTML tags by
replacing characters that are reserved in HTML with HTML entity equivalents
and inserting escape characters before unsafe JavaScript characters.
JSINHTMLENCODE(someValue) is a convenience function that is
equivalent to JSENCODE(HTMLENCODE((someValue)). That is,
JSINHTMLENCODE first encodes someValue with HTMLENCODE, and
then encodes the result with JSENCODE.
LEFT Returns the specified number of characters from the beginning of a text string.
LOWER Converts all letters in the specified text string to lowercase. Any characters that
aren’t letters are unaffected by this function. Locale rules are applied if a locale
is provided.
LPAD Inserts characters that you specify to the left-side of a text string.
MID Returns the specified number of characters from the middle of a text string given
the starting position.
37
Examples of Advanced Formula Fields Formula Operators and Functions by Context
Function Description
RIGHT Returns the specified number of characters from the end of a text string.
RPAD Inserts characters that you specify to the right-side of a text string.
TEXT Converts a percent, number, date, date/time, or currency type field into text
anywhere formulas are used. Also, converts picklist values to text in approval
rules, approval step rules, workflow rules, escalation rules, assignment rules,
auto-response rules, validation rules, formula fields, field updates, and custom
buttons and links.
TRIM Removes the spaces and tabs from the beginning and end of a text string.
UPPER Converts all letters in the specified text string to uppercase. Any characters that
aren’t letters are unaffected by this function. Locale rules are applied if a locale
is provided.
URLENCODE Encodes text and merge field values for use in URLs by replacing characters that
are illegal in URLs, such as blank spaces, with the code that represent those
characters as defined in RFC 3986, Uniform Resource Identifier (URI): Generic Syntax.
For example, blank spaces are replaced with %20, and exclamation points are
replaced with %21.
Summary Functions
These functions are available with summary, matrix, and joined reports.
Function Description
PARENTGROUPVAL Returns the value of a specified parent grouping. A “parent” grouping is any level
above the one containing the formula. You can use this function only in custom
summary formulas and at grouping levels for reports, but not at summary levels.
PREVGROUPVAL Returns the value of a specified previous grouping. A “previous” grouping is one
that comes before the current grouping in the report. Choose the grouping level
and increment. The increment is the number of columns or rows before the
current summary. The default is 1, the maximum is 12. You can use this function
only in custom summary formulas and at grouping levels for reports, but not at
summary levels.
Advanced Functions
Function Description
CURRENCYRATE Returns the conversion rate to the corporate currency for the given currency ISO
code. If the currency is invalid, returns 1.0.
38
Examples of Advanced Formula Fields Formula Operators and Functions by Context
Function Description
GETRECORDIDS Returns an array of strings in the form of record IDs for the selected records in a
list, such as a list view or related list.
IMAGEPROXYURL Securely retrieves external images, and prevents unauthorized requests for user
credentials.
INCLUDE Returns content from an s-control snippet. Use this function to reuse common
code in many s-controls.
ISCHANGED Compares the value of a field to the previous value, and returns TRUE if the values
are different. If the values are the same, returns FALSE.
LINKTO Returns a relative URL in the form of a link (href and anchor tags) for a custom
s-control or Salesforce page.
PREDICT Returns an Einstein Discovery prediction for a record based on the specified
record ID or for a list of fields and their values.
REGEX Compares a text field to a regular expression, and returns TRUE if there’s a match.
Otherwise, returns FALSE. A regular expression is a string used to describe a
format of a string according to certain syntax rules.
REQUIRESCRIPT Returns a script tag with source for a URL that you specify. Use this function
when referencing the Lightning Platform AJAX Toolkit or other JavaScript toolkits.
URLFOR Returns a relative URL for an action, s-control, Visualforce page, or a file in a static
resource archive in a Visualforce page.
VLOOKUP Returns a value by looking up a related value on a custom object similar to the
VLOOKUP() Excel function.
39