0% found this document useful (0 votes)
3 views

SF_formulas_cheatsheet

Salesforce training guide

Uploaded by

mrchombers
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

SF_formulas_cheatsheet

Salesforce training guide

Uploaded by

mrchombers
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

App Logic Formulas Cheat Sheet

Overview Text Operators


A formula is an expression that derives its value from other fields, expressions, or values.
Formulas can be used in a number of contexts, such as custom fields for auto-calculating & Concatenates two or more strings.
values, as criteria for data validation and workflow, as well as the expression language
in Visualforce. Date and Time Functions
Getting Started
DATE Returns a date value from year, month, and day values you enter.
You can build formulas if you’re using a part of the Force.com platform that supports them. Salesforce displays an error on the detail page if the value of the
For example, when creating a new field you can create a validation rule that determines DATE function in a formula field is an invalid date, such as
when data is valid: February 29 in a non-leap year.

AND(LEN(AccountNumber__c) > 0, NOT(ISNUMBER(AccountNumber__c)))


DATEVALUE Returns a year, month, day and GMT time value.
In Visualforce you can use formulas in any component that supports expressions by including
the formula inside {! } characters. Here’s an example of a Visualforce page that dynamically DAY Returns a day of the month in the form of a number between
renders as a PDF or HTML, depending on whether a parameter “render” is passed: 1 and 31.
<apex:page renderAs="{!IF($CurrentPage.Parameters.render ==
'pdf','pdf',null)}"> MONTH Returns the month, a number between 1 ( January) and 12
(December) in number format of a given date.
      Something here...
</apex:page> NOW Returns a date/time representing the current moment.
You can also create fields of type formula, to auto-calculate values within a record.
For example, here’s one calculating a line item value: TODAY Returns the current date as a date data type.
Unit_Price__c * Units_Sold__c
YEAR Returns the four-digit year in number format of a given date.
Not all formula functions are supported in all contexts.
Informational Functions
Math Operators
ISBLANK Determines whether an expression has a value and returns TRUE if
+ Calculates the sum of two values. it does not. If it contains a value, this function returns FALSE.
- Calculates the difference of two values.
BLANKVALUE Determines whether an expression has a value and returns a
* Multiplies its values. substitute expression if it does not. If the expression has a value,
returns the value of the expression.
/ Divides its values.
PRIORVALUE Returns the previous value of a field.
^ Raises a number to a power of a specified number.

()
Logical Functions
Specifies that the expressions within the open parenthesis and close
parenthesis are evaluated first. All other expressions are evaluated
using standard operator precedence. AND Returns TRUE response if all values are true; returns a
FALSE response if one or more values are false.
Logical Operators
CASE Checks a given expression against a series of values. If the expression
is equal to a value, returns the corresponding
= and == Evaluates whether two values are equivalent. result. If it is not equal to any values, it returns the else_result.
<> and != Evaluates whether two values are not equivalent. IF Determines whether expressions are true or false. Returns a given
value if true and another if false.
< Evaluates whether a value is less than the value that follows this
symbol.
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,
Evaluates whether a value is greater than the value that follows
this function returns FALSE.
this symbol.

<= ISNEW Checks whether the formula is running during the creation of a
Evaluates whether a value is less than or equal to the value that
follows this symbol. new record and returns TRUE if it is. If an existing record is being
updated, this function returns FALSE.
>= Evaluates whether a value is greater than or equal to the value that
follows this symbol. ISNUMBER Determines whether a text value is a number and returns
TRUE if it is. Otherwise, it returns FALSE.
&& Evaluates whether two values or expressions are both true.
Use this operator as an alternative to the logical function AND. NOT Returns FALSE for TRUE and TRUE for FALSE.

|| Evaluates whether at least one of multiple values or expressions is OR Determines whether expressions are true or false. Returns TRUE if
true. Use this operator as an alternative to the logical function OR. any expression is true. Returns FALSE if all expressions are false.

http://developer.salesforce.com
Math Functions Text Functions

ABS Calculates the absolute value of a number. The absolute value of a BEGINS Determines whether text begins with specific characters and
number is the number without its positive or negative sign. returns TRUE if it does. Returns FALSE if it does not.

CEILING Rounds a number up to the nearest integer.


BR Inserts a line break in a string of text.
EXP Returns a value for e raised to the power of a number you specify.
CASESAFEID Converts a 15-character ID to a case-insensitive 18-character ID.
FLOOR Returns a number rounded down to the nearest integer.
CONTAINS Compares two arguments of text and returns TRUE if the first
LN Returns the natural logarithm of a specified number. Natural argument contains the second argument. If not, returns FALSE.
logarithms are based on the constant e value of 2.71828182845904.
FIND Returns the position of a string within a string of text represented
LOG Returns the base 10 logarithm of a number. as a number.

MAX Returns the highest number from a list of numbers. GETSESSIONID Returns the user’s session ID.

MIN Returns the lowest number from a list of numbers. HYPERLINK Creates a link to a URL from the specified text.

MOD Returns a remainder after a number is divided by a specified divisor. IMAGE Inserts an image with alternate text and height/width
specifications.
ROUND Returns the nearest number to a number you specify, constraining
the new number by a specified number of digits. INCLUDES Determines whether any value selected in a multi-select picklist
field equals a text literal you specify.
SQRT Returns the positive square root of a given number.
ISPICKVAL
Advanced Functions Determines whether the value of a picklist field is equal to a text
literal you specify.

LEFT Returns the specified number of characters from the beginning of


GETRECORDIDS Returns an array of strings in the form of record IDs for the
a text string.
selected records in a list, such as a list view or related list.
LEN Returns the number of characters in a specified text string.
INCLUDE Returns content from an s-control snippet. Use this function
to reuse common code in many s-controls.
LOWER Converts all letters in the specified text string to lowercase.
LINKTO
Any characters that are not letters are unaffected by this function.
Returns a relative URL in the form of a link (href and anchor tags)
Locale rules are applied if a locale is provided.
for a custom s-control or Salesforce page.
LPAD Inserts your specified characters to the left side of a text string.
REGEX Compares a text field to a regular expression and returns
TRUE if there is a match. Otherwise, it returns FALSE. A
MID Returns the specified number of characters from the middle of a
regular expression is a string used to describe a format of a string
according to certain syntax rules. text string given the starting position.

RIGHT Returns the specified number of characters from the end of a text
REQUIRESCRIPT Returns a script tag with source for a URL you specify. Use
this function when referencing the Force.com AJAX Toolkit or string.
other JavaScript toolkits.
RPAD Inserts your specified characters to the right side of a text string.
URLFOR Returns a relative URL for an action, s-control, or a file in a static
resource archive in a Visualforce page. SUBSTITUTE Substitutes new text for old text in a text string.

VLOOKUP Returns a value by looking up a related value on a custom object TEXT Converts a percent, number, date, date/time, or currency type field
similar to the VLOOKUP() Excel function. into text anywhere formulas are used. Also, converts picklist values
to text in validation rules, formula fields, and field updates.
Encoding Functions
TRIM Removes the spaces and tabs from the beginning and end of a
text string.
HTMLENCODE Encodes text and merge field values for use in HTML by replacing
characters that are reserved in HTML, such as the greater-than UPPER Converts all letters in the specified text string to uppercase.
sign (>), with HTML entity equivalents, such as &gt;. Any characters that are not letters are unaffected by this function.
Locale rules are applied if a locale is provided.
JSENCODE Encodes text and merge field values for use in JavaScript by
inserting escape characters, such as a backslash (\), before unsafe VALUE Converts a text string to a number.
JavaScript characters, such as the apostrophe (‘).

JSINHTMLENCODE Encodes text and merge field values for use in JavaScript within
Summary Functions
HTML tags by inserting escape characters before unsafe JavaScript
characters and replacing characters that are reserved in HTML Only used in the context of creating custom summary formulas for summary reports.
with HTML entity equivalents.
PARENTGROUPVAL A summary function that returns the value of the selected
URLENCODE Encodes text and merge field values for use in URLs by replacing summary field from the parent grouping level that you specify.
characters that are illegal in URLs, such as blank spaces, with
the code that represent those characters as defined in RFC 3986, PREVGROUPVAL A summary function that returns the value of the selected
Uniform Resource Identifier (URI): Generic Syntax. For example,
summary field from the previous summary row at the grouping
blank spaces are replaced with %20, and exclamation points are
level that you specify.
replaced with %21.

For other cheatsheets: http://developer.force.com/cheatsheets 11182013

You might also like