Functions must be used in a Visualforce expression to be evaluated. You can use the following functions in your Visualforce pages.
The date/time data type might not evaluate correctly in formula expressions for Visualforce pages with an API version less than 20.0. It may be incorrectly interpreted as just a date type.
Function | Description | Use |
---|---|---|
ADDMONTHS | Returns the date that is the indicated number of months before or after a specified date. If the resulting month has fewer days than the start month, then the function returns the last day of the resulting month. Otherwise, the result has the same day component as the specified date. | ADDMONTHS (date, num) and replace date with the start date and num with the number of months to be added. |
DATE | Returns a date value from year, month, and day values 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. | DATE(year,month,day) and replace year with a four-digit year, month with a two-digit month, and day with a two-digit day. |
DATEVALUE | Returns a date value for a date/time or text expression. | DATEVALUE(expression) and replace expression with a date/time or text value, merge field, or expression. |
DATETIMEVALUE | Returns a year, month, day and GMT time value. | DATETIMEVALUE(expression) and replace expression with a date/time or text value, merge field, or expression. |
DAY | Returns a day of the month in the form of a number between 1 and 31. | DAY(date) and replace date with a date field or value such as TODAY(). |
HOUR | Returns the local time hour value without the date in the form of a number from 1 through 12. | HOUR(time) and replace time with a time value or value such as TIMENOW(). |
MILLISECOND | Returns a milliseconds value in the form of a number from 0 through 999. | MILLISECOND(time) and replace time with a time value or value such as TIMENOW(). |
MINUTE | Returns a minute value in the form of a number from 0 through 60. | MINUTE(time) and replace time with a time value or value such as TIMENOW(). |
MONTH | Returns the month, a number between 1 (January) and 12 (December) in number format of a given date. | MONTH(date) and replace date with the field or expression for the date containing the month you want returned. |
NOW | Returns a date/time representing the current moment.
The NOW function returns the current
date and time in the GMT timezone. {!NOW()} For example:
Today's date and time is: {!NOW()} Today's date and time is: Mon Jul 21 16:12:10 GMT 2008
Tips
|
NOW() |
SECOND | Returns a seconds value in the form of a number from 0 through 60. | SECOND(time) and replace time with a time value or value such as TIMENOW(). |
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. | TIMENOW() |
TIMEVALUE | Returns the local time value without the date, such as business hours. | TIMEVALUE(value) and replace value with a date/time or text value, merge field, or expression. |
TODAY | Returns the current date as a date data type. The TODAY function returns the
current day. For example, The following markup:
Today's date is: {!TODAY()} Today's date is: Mon Jul 21 00:00:00 GMT 2008 Tips
|
TODAY() |
WEEKDAY | Returns the day of the week for the given date, using 1 for Sunday, 2 for Monday, through 7 for Saturday. | WEEKDAY(date) |
YEAR | Returns the four-digit year in number format of a given date. | YEAR(date) and replace date with the field or expression that contains the year you want returned. |
Function | Description | Use |
---|---|---|
ABS | Calculates the absolute value of a number. The absolute value of a number is the number without its positive or negative sign. | ABS(number) and replace number with a merge field, expression, or other numeric value that has the sign you want removed. |
CEILING | Rounds a number up to the nearest integer, away from zero if negative. | CEILING(number) and replace number with the field or expression you want rounded. |
EXP | Returns a value for e raised to the power of a number you specify. | EXP(number) and replace number with a number field or value such as 5. |
FLOOR | Returns a number rounded down to the nearest integer, towards zero if negative. | FLOOR(number) and replace number with a number field or value such as 5.245. |
LN | Returns the natural logarithm of a specified number. Natural logarithms are based on the constant e value of 2.71828182845904. | LN(number) and replace number with the field or expression for which you want the natural logarithm. |
LOG | Returns the base 10 logarithm of a number. | LOG(number) and replace number with the field or expression from which you want the base 10 logarithm calculated. |
MAX | Returns the highest number from a list of numbers. | MAX(number, number,...) and replace number with the fields or expressions from which you want to retrieve the highest number. |
MCEILING | Rounds a number up to the nearest integer, towards zero if negative. | MCEILING(number) |
MFLOOR | Rounds a number down to the nearest integer, away from zero if negative. | MFLOOR(number) |
MIN | Returns the lowest number from a list of numbers. | MIN(number, number,...) and replace number with the fields or expressions from which you want to retrieve the lowest number. |
MOD | Returns a remainder after a number is divided by a specified divisor. | MOD(number, divisor) and replace number with the field or expression you want divided; replace divisor with the number to use as the divisor. |
ROUND | Returns the nearest number to a number you specify, constraining the new number by a specified number of digits. | ROUND(number, num_digits) and replace number with the field or expression you want rounded; replace num_digits with the number of decimal places you want to consider when rounding. |
SQRT | Returns the positive square root of a given number. | SQRT(number) and replace number with the field or expression you want computed into a square root. |
Function | Description | Use |
---|---|---|
BEGINS | Determines if text begins with specific characters and
returns TRUE if it does. Returns FALSE if it does not. The following markup will return true if the opportunity
StageName field begins with the string
“Closed”. Standard stage names “Closed Won” and
“Closed Lost” would both return
true.
{!BEGINS(opportunity.StageName, 'Closed')}
This function is case sensitive so be sure your compare_text value has the correct capitalization. Also, this function only works with text, not with numbers or other data types. |
BEGINS(text, compare_text) and replace text, compare_text with the characters or fields you want to compare. |
BR | Inserts a line break in a string of text. | BR() |
CASESAFEID | Converts a 15-character ID to a case-insensitive 18-character ID. | CASESAFEID(id) and replace id with the object’s ID. |
CONTAINS | Compares two arguments of text and returns TRUE if the
first argument contains the second argument. If not, returns FALSE. The following example 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.”
{!IF(contains(opportunity.Product_Type__c, "part"), "Parts", "Service")} This function is case sensitive so be sure your compare_text value has the correct capitalization. |
CONTAINS(text, compare_text) and replace text with the text that contains the value of compare_text. |
FIND | Returns the position of a string within a string of text represented as a number. | FIND(search_text, text[, start_num]) and replace search_text with the string you want to find, replace text with the field or expression you want to search, and replace start_num with the number of the character from which to start searching from left to right. |
GETSESSIONID | Returns the user’s session ID. | GETSESSIONID() |
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 >. | {!HTMLENCODE(text)} and replace text with the merge field or text string that contains the reserved characters. |
ISPICKVAL | Determines if the value of a picklist field is equal to a text literal you specify. | ISPICKVAL(picklist_field, text_literal) and replace picklist_field with the merge field name for the picklist; replace text_literal with the picklist value in quotes. text_literal cannot be a merge field or the result of a function. |
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 ('). | {!JSENCODE(text)} and replace text with the merge field or text string that contains the unsafe JavaScript characters. |
JSINHTMLENCODE | 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. | {!JSINHTMLENCODE(text)} and replace text with the merge field or text string that contains the unsafe JavaScript characters. |
LEFT | Returns the specified number of characters from the beginning of a text string. | LEFT(text, num_chars) and replace text with the field or expression you want returned; replace num_chars with the number of characters from the left you want returned. |
LEN | Returns the number of characters in a specified text
string. {!LEN(Account.name)} returns the number of characters in the Account name. LEN counts spaces as well as characters. {!LEN("The Spot")} returns 8. |
LEN(text) and replace text with the field or expression whose length you want returned. |
LOWER | Converts all letters in the specified text string to lowercase. Any characters that are not letters are unaffected by this function. Locale rules are applied if a locale is provided. | LOWER(text, [locale]) and replace text with the field or text you wish to convert to lowercase, and locale with the optional two-character ISO language code or five-character locale code, if available. |
LPAD | Inserts characters you specify to the left-side of a text string. |
LPAD(text,
padded_length[, pad_string])
and replace the variables:
|
MID | Returns the specified number of characters from the middle of a text string given the starting position. | MID(text, start_num, num_chars) and replace text with the field or expression to use when returning characters; replace start_num with the number of characters from the left to use as a starting position; replace num_chars with the total number of characters to return. |
RIGHT | Returns the specified number of characters from the end of a text string. | RIGHT(text, num_chars) and replace text with the field or expression you want returned; replace num_chars with the number of characters from the right you want returned. |
RPAD | Inserts characters that you specify to the right-side of a text string. |
RPAD(text,
padded_length[, 'pad_string'])
and replace the variables:
|
SUBSTITUTE | Substitutes new text for old text in a text string. | SUBSTITUTE(text, old_text, new_text) and replace text with the field or value for which you want to substitute values, old_text with the text you want replaced, and new_text with the text you want to replace the old_text. |
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. | TEXT(value) and replace value with the field or expression you want to convert to text format. Avoid using any special characters besides a decimal point (period) or minus sign (dash) in this function. |
TRIM | Removes the spaces and tabs from the beginning and end of a text string. | TRIM(text) and replace text with the field or expression you want to trim. |
UPPER | Converts all letters in the specified text string to uppercase. Any characters that are not letters are unaffected by this function. Locale rules are applied if a locale is provided. | UPPER(text, [locale]) and replace text with the field or expression you wish to convert to uppercase, and locale with the optional two-character ISO language code or five-character locale code, if available. |
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. | {!URLENCODE(text)} and replace text with the merge field or text string that you want to encode. |
VALUE | Converts a text string to a number. | VALUE(text) and replace text with the field or expression you want converted into a number. |
Function | Description | Use |
---|---|---|
CURRENCYRATE | Returns the conversion rate to the corporate currency for the given currency ISO code. If the currency is invalid, returns 1.0. | CURRENCYRATE(currency_ISO_code) and replace currency_ISO_code with a currency ISO code, such as “USD”. |
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. | {!GETRECORDIDS(object_type)} and replace object_type with a reference to the custom or standard object for the records you want to retrieve. |
INCLUDE | Returns content from an s-control snippet. Use this function to reuse common code in many s-controls. | {!INCLUDE(source, [inputs])} and replace source with the s-control snippet you want to reference. Replace inputs with any information you need to pass to the snippet. |
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, this function returns FALSE. | ISCHANGED(field) and replace field with the name of the field you want to compare. |
JUNCTIONIDLIST | Returns a JunctionIDList based on the provided IDs. | JUNCTIONIDLIST(id, id,...) and replace id with the Salesforce ID you want to use. |
LINKTO | Returns a relative URL in the form of a link (href and anchor tags) for a custom s-control or Salesforce page. | {!LINKTO(label, target, id, [inputs], [no override]} and replace label with the text for the link, target with the URL, and id with a reference to the record. Inputs are optional and can include any additional parameters you want to add to the link. The no override argument is also optional and defaults to “false.” It applies to targets for standard Salesforce pages such as $Action.Account.New. Replace no override with “true” when you want to display a standard Salesforce page regardless of whether you have defined an override for it elsewhere. |
REGEX | Compares a text field to a regular expression and returns TRUE if there is a match. Otherwise, it returns FALSE. A regular expression is a string used to describe a format of a string according to certain syntax rules. | REGEX(text, regex_text) and replace text with the text field, and regex_text with the regular expression you want to match. |
REQUIRESCRIPT | Returns a script tag with source for a URL you specify. Use this function when referencing the Lightning Platform AJAX Toolkit or other JavaScript toolkits. | {!REQUIRESCRIPT(url)} and replace url with the link for the script that is required. |
URLFOR | Returns a relative URL for an action, s-control, Visualforce
page, or a file in a static resource archive in a Visualforce page. This can be used to return a reference to a file contained in a static resource archive (such as a .zip or .jar file). {!URLFOR(resource, path)} Replace resource with the name of the static resource archive expressed as a merge variable (for example, $Resource.resourceName), andpath with the local path to the file in the archive that you want to reference. |
{!URLFOR(target, [id],
[inputs], [no override])} and
replace target with the URL or action, s-control, or static
resource merge variable, id with an optional reference to the
record, and inputs with any optional parameters. The no override argument is also optional
and defaults to “false.” It applies to targets for standard Salesforce pages such as
$Action.Account.New. Replace no override with
“true” when you want to display a standard Salesforce page regardless of whether
you have defined an override for it elsewhere.
The input values can be dynamic. For example, to include an account ID,
specify:
{!URLFOR($Page.myVisualforcePage, null, [accountId=Account.Id])} The resulting URL would include a parameter with the ID, such as: https://instance.salesforce.com/apex/myVisualforcePage?accountId=001B0000002txol You can also use non-string variables, like an SObject variable. For example, if you supply [myAccountParam=Account], the value is converted to a string and the URL would contain ?MyAccountParam=001B0000002txol. You can also use a parameter to supply a static value, such as [param1=55]. ![]() NoteBecause parameter names are static, you can’t use a variable to determine the parameter name. For example, if you use [myVariable=”value1”] and set “myVariable” to param1, the resulting URL includes ?myVariable=value1 and not the “param1” value. |
VLOOKUP | Returns a value by looking up a related value on a custom object similar to the VLOOKUP() Excel function. | VLOOKUP(field_to_return, field_on_lookup_object, lookup_value) and replace field_to_return with the field that contains the value you want returned, field_on_lookup_object with the field on the related object that contains the value you want to match, and lookup_value with the value you want to match. You can only use VLOOKUP() in validation rules. If the function fails because, for example, the field_on_lookup_object doesn’t exist, you can specify an error message in the validation rule itself. |