0% found this document useful (0 votes)
12 views28 pages

Untitled Document

The document provides a comprehensive overview of various logical, text, and math functions used in formulas, including their descriptions, use cases, and examples. It covers functions like AND, OR, IF, and mathematical operations such as ABS, CEILING, and DISTANCE. Additionally, it includes practical examples for validation rules and a summary table for quick reference.

Uploaded by

dhaneshdeore
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views28 pages

Untitled Document

The document provides a comprehensive overview of various logical, text, and math functions used in formulas, including their descriptions, use cases, and examples. It covers functions like AND, OR, IF, and mathematical operations such as ABS, CEILING, and DISTANCE. Additionally, it includes practical examples for validation rules and a summary table for quick reference.

Uploaded by

dhaneshdeore
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

#.

Logical

1. Logical Functions

● AND: Returns TRUE if all arguments are TRUE.


Example: AND(condition1, condition2)
● OR: Returns TRUE if any argument is TRUE.
Example: OR(condition1, condition2)
● NOT: Returns the logical opposite of the argument.
Example: NOT(condition)
● IF: Returns one value if a condition is TRUE and another if it's FALSE.
Example: IF(condition, value_if_true, value_if_false)

1. BLANKVALUE(expression, substitute_value)

● Description: Checks if the expression is blank. If it is, it returns the


substitute_value; otherwise, it returns the expression.
● Use Case: Useful for providing a default value when a field is blank.

Example:
text
Copy code
BLANKVALUE(Phone, "No Phone Provided")

● If Phone is blank, it will return "No Phone Provided."

2. ISBLANK(expression)

● Description: Returns TRUE if the expression is blank; otherwise, it returns FALSE.


● Use Case: To check if a required field is blank.

Example:
text
Copy code
ISBLANK(Email)

● Triggers an error if the Email field is blank.

3. ISCLONE()

● Description: Returns TRUE if the record is being cloned.


● Use Case: To apply special rules for cloned records.
Example:
text
Copy code
ISCLONE()

● Use this in combination with other functions to ensure unique field values in cloned
records.

4. ISNEW()

● Description: Returns TRUE if the record is being created for the first time.
● Use Case: To enforce rules only during record creation.

Example:
text
Copy code
ISNEW() && ISBLANK(Name)

● Triggers an error if the Name field is blank during record creation.

5. ISNULL(expression)

● Description: Returns TRUE if the expression is null; otherwise, it returns FALSE.


Note: Deprecated for most use cases, use ISBLANK() instead.
● Use Case: Older validation rules may still use this to check null values.

Example:
text
Copy code
ISNULL(Amount)

● Triggers an error if Amount is null.

6. ISNUMBER(text)

● Description: Returns TRUE if the text value is a number; otherwise, it returns


FALSE.
● Use Case: To validate that a text field contains only numeric values.

Example:
text
Copy code
ISNUMBER(AccountNumber)
● Ensures that AccountNumber contains only numeric characters.

7. NULLVALUE(expression, substitute_value)

● Description: Checks if the expression is null. If it is, it returns the


substitute_value; otherwise, it returns the expression.
Note: Deprecated, use BLANKVALUE() instead.
● Use Case: To substitute a default value for null fields.

Example:
text
Copy code
NULLVALUE(Phone, "Unknown")

● Returns "Unknown" if Phone is null.

8. PRIORVALUE(field)

● Description: Returns the previous value of a field before it was updated.


● Use Case: To compare the old and new values of a field.

Example:
text
Copy code
PRIORVALUE(Amount) > 1000

● Triggers an error if the previous Amount value was greater than 1000.

Practical Examples
Prevent Cloning of Certain Records
text
Copy code
ISCLONE()

1. Triggers an error when a user tries to clone the record.

Validate a Required Field for New Records


text
Copy code
ISNEW() && ISBLANK(Name)

2. Ensures the Name field is filled during record creation.


Compare Old and New Values
text
Copy code
PRIORVALUE(Amount) > 1000 && Amount < 1000

3. Triggers an error if the Amount field was previously greater than 1000 but is now set
below 1000.

#. TEXT

1. BEGIN(text, compare_text)

● Description: Checks if text starts with compare_text.


● Use Case: Validate text that starts with a specific value.

Example:
text
Copy code
BEGINS(Name, "A")

● Returns TRUE if the Name starts with "A."

2. CONTAINS(text, compare_text)

● Description: Checks if text contains the substring compare_text.


● Use Case: Validate fields that must contain specific characters.

Example:
text
Copy code
CONTAINS(Email, "@")

● Ensures that the Email field contains the "@" symbol.

3. ISPICKVAL(field, value)
● Description: Checks if a picklist field equals the specified value.
● Use Case: Validate picklist fields.

Example:
text
Copy code
ISPICKVAL(Status, "Closed")

● Returns TRUE if the Status is "Closed."

4. TEXT(field)

● Description: Converts a field value (e.g., picklist or number) to text.


● Use Case: Useful for combining text with other field values.

Example:
text
Copy code
TEXT(Amount)

● Converts the Amount field to text.

5. INCLUDES(multi-select_picklist, value)

● Description: Checks if a multi-select picklist contains a specific value.


● Use Case: Validate multi-select picklists.

Example:
text
Copy code
INCLUDES(Regions, "North")

● Returns TRUE if "North" is selected in the Regions field.

6. ASCII(text)

● Description: Returns the ASCII code of the first character in the text.
● Use Case: Analyze or validate text at a character level.

Example:
text
Copy code
ASCII("A")

● Returns 65 (ASCII code for "A").

7. BR()

● Description: Inserts a line break in a formula output (primarily used in formula fields,
not validation rules).

Example:
text
Copy code
"Line1" & BR() & "Line2"
Displays:
Copy code
Line1
Line2

8. CASESAFEID(id)

● Description: Converts a 15-character ID to an 18-character case-insensitive ID.


● Use Case: Standardize Salesforce IDs.

Example:
text
Copy code
CASESAFEID(Id)

9. CHR(number)

● Description: Returns the character associated with the ASCII code.


● Use Case: Generate specific characters programmatically.

Example:
text
Copy code
CHR(65)
● Returns "A".

10. FIND(substring, text, start_num)

● Description: Finds the position of a substring in text starting from start_num.


● Use Case: Validate text structure.

Example:
text
Copy code
FIND("@", Email, 1)

● Returns the position of "@" in the Email field.

11. GETSESSIONID()

● Description: Returns the session ID of the logged-in user (primarily for use in
formula fields).
● Use Case: Rarely used in validation rules.

12. INITCAP(text)

● Description: Capitalizes the first letter of each word.


● Use Case: Standardize text formats.

Example:
text
Copy code
INITCAP("salesforce formula")

● Returns "Salesforce Formula".

13. LEFT(text, num_chars)

● Description: Returns the first num_chars characters of text.


● Use Case: Validate or extract parts of text.

Example:
text
Copy code
LEFT(Name, 3)

● Returns the first 3 characters of Name.

14. LEN(text)

● Description: Returns the length of the text.


● Use Case: Validate text length.

Example:
text
Copy code
LEN(Phone)

● Returns the number of characters in Phone.

15. LOWER(text)

● Description: Converts text to lowercase.


● Use Case: Normalize text for comparison.

Example:
text
Copy code
LOWER("SALESFORCE")

● Returns "salesforce".

16. LPAD(text, padded_length, pad_string)

● Description: Pads text on the left with a specified string.


● Use Case: Format numbers or text.

Example:
text
Copy code
LPAD("123", 5, "0")

● Returns "00123".
17. MID(text, start_num, num_chars)

● Description: Returns a substring from text, starting at start_num, for


num_chars.
● Use Case: Extract parts of text.

Example:
text
Copy code
MID(Name, 2, 3)

● Returns 3 characters starting from the second character of Name.

18. PICKLISTCOUNT(multi-select_picklist)

● Description: Returns the number of selected values in a multi-select picklist.


● Use Case: Validate multi-select fields.

Example:
text
Copy code
PICKLISTCOUNT(Regions)

19. REVERSE(text)

● Description: Reverses the characters in text.


● Use Case: Format or analyze text.

Example:
text
Copy code
REVERSE("Salesforce")

● Returns "ecrofelasS".

20. RIGHT(text, num_chars)

● Description: Returns the last num_chars of text.


● Use Case: Extract suffixes or endings.
Example:
text
Copy code
RIGHT(Name, 3)

21. RPAD(text, padded_length, pad_string)

● Description: Pads text on the right with a specified string.

Example:
text
Copy code
RPAD("123", 5, "0")

● Returns "12300".

22. SUBSTITUTE(text, old_text, new_text)

● Description: Replaces occurrences of old_text in text with new_text.


● Use Case: Correct or standardize text.

Example:
text
Copy code
SUBSTITUTE(Phone, "-", "")

● Removes hyphens from Phone.

23. TRIM(text)

● Description: Removes leading and trailing spaces.


● Use Case: Clean up text.

Example:
text
Copy code
TRIM(" Hello ")

● Returns "Hello".
24. UPPER(text)

● Description: Converts text to uppercase.


● Use Case: Normalize text.

Example:
text
Copy code
UPPER("salesforce")

25. VALUE(text)

● Description: Converts a text string to a number.


● Use Case: Perform calculations on numeric text.

Example:
text
Copy code
VALUE("123")

● Returns 123.

#. Math Functions

1. ABS(number)

● Description: Returns the absolute value of a number (removes the sign).


● Use Case: Ensure only positive values are considered in calculations.

Example:
text
Copy code
ABS(-5)

● Returns 5.
2. ACOS(number)

● Description: Returns the arccosine (inverse cosine) of a number in radians.


● Use Case: For advanced mathematical or trigonometric calculations.

Example:
text
Copy code
ACOS(0.5)

● Returns 1.047 (in radians).

3. ASIN(number)

● Description: Returns the arcsine (inverse sine) of a number in radians.

Example:
text
Copy code
ASIN(0.5)

● Returns 0.524 (in radians).

4. ATAN(number)

● Description: Returns the arctangent (inverse tangent) of a number in radians.

Example:
text
Copy code
ATAN(1)

● Returns 0.785 (in radians).

5. ATAN2(x, y)

● Description: Returns the arctangent of the quotient of its two arguments (in radians).
● Use Case: Useful for calculating angles from coordinates.

Example:
text
Copy code
ATAN2(1, 1)

● Returns 0.785 (in radians).

6. CEILING(number)

● Description: Rounds a number up to the nearest whole number.

Example:
text
Copy code
CEILING(4.2)

● Returns 5.

7. COS(number)

● Description: Returns the cosine of a number (in radians).


● Use Case: For trigonometric calculations.

Example:
text
Copy code
COS(PI())

● Returns -1.

8. DISTANCE(fromLocation, toLocation, unit)

● Description: Calculates the distance between two geolocation points.


● Use Case: Useful for geolocation-based validations.

Example:
text
Copy code
DISTANCE(GEOLOCATION(37.7749, -122.4194), GEOLOCATION(34.0522,
-118.2437), "mi")

● Returns the distance in miles between San Francisco and Los Angeles.
9. EXP(number)

● Description: Returns e raised to the power of the number.


● Use Case: Exponential growth calculations.

Example:
text
Copy code
EXP(1)

● Returns 2.718.

10. FLOOR(number)

● Description: Rounds a number down to the nearest whole number.

Example:
text
Copy code
FLOOR(4.8)

● Returns 4.

11. GEOLOCATION(latitude, longitude)

● Description: Represents a geolocation point with latitude and longitude.


● Use Case: Combine with DISTANCE to validate geolocation fields.

Example:
text
Copy code
GEOLOCATION(37.7749, -122.4194)

12. LN(number)

● Description: Returns the natural logarithm of a number (base e).

Example:
text
Copy code
LN(10)

● Returns 2.302.

13. LOG(number, base)

● Description: Returns the logarithm of a number in the specified base.

Example:
text
Copy code
LOG(100, 10)

● Returns 2.

14. MAX(number1, number2, ...)

● Description: Returns the largest number from the inputs.

Example:
text
Copy code
MAX(10, 20, 5)

● Returns 20.

15. MIN(number1, number2, ...)

● Description: Returns the smallest number from the inputs.

Example:
text
Copy code
MIN(10, 20, 5)

● Returns 5.

16. MOD(number, divisor)


● Description: Returns the remainder of a division operation.
● Use Case: Validate divisibility or odd/even checks.

Example:
text
Copy code
MOD(10, 3)

● Returns 1.

17. PI()

● Description: Returns the constant value of π (approximately 3.14159).


● Use Case: Trigonometric calculations.

Example:
text
Copy code
PI()

● Returns 3.14159.

18. ROUND(number, num_digits)

● Description: Rounds a number to the specified number of decimal places.

Example:
text
Copy code
ROUND(4.567, 2)

● Returns 4.57.

19. SIN(number)

● Description: Returns the sine of a number (in radians).

Example:
text
Copy code
SIN(PI()/2)
● Returns 1.

20. TAN(number)

● Description: Returns the tangent of a number (in radians).

Example:
text
Copy code
TAN(PI()/4)

● Returns 1.

21. TRUNC(number, num_digits)

● Description: Truncates a number to the specified number of decimal places without


rounding.

Example:
text
Copy code
TRUNC(4.567, 2)

● Returns 4.56.

Summary Table
Function Description Example Result

ABS Absolute value ABS(-5) 5

ACOS Arccosine (radians) ACOS(0.5) 1.047

ASIN Arcsine (radians) ASIN(0.5) 0.524

ATAN Arctangent (radians) ATAN(1) 0.785

ATAN2 Arctangent from x and y ATAN2(1, 1) 0.785

CEILING Rounds up CEILING(4.2) 5

DISTANCE Distance between two locations See example Varies


EXP Exponential EXP(1) 2.718

FLOOR Rounds down FLOOR(4.8) 4

LN Natural logarithm LN(10) 2.302

LOG Logarithm (base x) LOG(100, 10) 2

MAX Largest number MAX(10, 20, 20


5)

MIN Smallest number MIN(10, 20, 5


5)

MOD Remainder MOD(10, 3) 1

PI Constant π PI() 3.141


59

ROUND Rounds to decimals ROUND(4.567, 4.57


2)

SIN Sine of angle SIN(PI()/2) 1

TAN Tangent of angle TAN(PI()/4) 1

TRUNC Truncate decimals without rounding TRUNC(4.567, 4.56


2)

#. Date and Time Functions

1. ADDMONTHS(date, num_months)

● Description: Adds a specified number of months to a given date.


● Use Case: Calculate future or past dates.

Example:
text
Copy code
ADDMONTHS(TODAY(), 3)

● Adds 3 months to the current date.


2. DATE(year, month, day)

● Description: Returns a date value for the specified year, month, and day.
● Use Case: Create a date from components.

Example:
text
Copy code
DATE(2025, 1, 1)

● Returns January 1, 2025.

3. DATETIMEVALUE(expression)

● Description: Converts a text or date expression into a Date/Time value.


● Use Case: Convert a date or text to a Date/Time field.

Example:
text
Copy code
DATETIMEVALUE("2025-01-01 14:30:00")

● Returns January 1, 2025, 2:30 PM.

4. DATEVALUE(expression)

● Description: Converts a Date/Time value to a Date-only value.


● Use Case: Extract the date portion of a Date/Time field.

Example:
text
Copy code
DATEVALUE(DATETIMEVALUE("2025-01-01 14:30:00"))

● Returns January 1, 2025.

5. DAY(date)

● Description: Returns the day of the month from a date.


● Use Case: Extract the day for specific logic.
Example:
text
Copy code
DAY(TODAY())

● Returns the day number of the current date.

6. DAYOFYEAR(date)

● Description: Returns the day of the year (1–365 or 1–366 for leap years).
● Use Case: Track the day in a year.

Example:
text
Copy code
DAYOFYEAR(DATE(2025, 1, 31))

● Returns 31.

7. FORMATDURATION(duration_in_seconds)

● Description: Formats a duration in seconds into hours, minutes, and seconds.


● Use Case: Display durations in a human-readable format.

Example:
text
Copy code
FORMATDURATION(3605)

● Returns 1:00:05.

8. FROMUNIXTIME(timestamp_in_seconds)

● Description: Converts a UNIX timestamp (in seconds) to a Date/Time value.


● Use Case: Handle epoch-based time values.

Example:
text
Copy code
FROMUNIXTIME(1672531200)

● Returns January 1, 2023.


9. HOUR(datetime)

● Description: Returns the hour (0–23) from a Date/Time value.


● Use Case: Extract the hour for scheduling or validation.

Example:
text
Copy code
HOUR(NOW())

10. ISOWEEK(date)

● Description: Returns the ISO week number of the year (1–53).


● Use Case: Standardized weekly tracking.

Example:
text
Copy code
ISOWEEK(TODAY())

11. ISOYEAR(date)

● Description: Returns the ISO year for the given date.


● Use Case: Handle ISO week-based years.

Example:
text
Copy code
ISOYEAR(TODAY())

12. MILLISECOND(datetime)

● Description: Returns the milliseconds (0–999) from a Date/Time value.


● Use Case: Rarely used in Salesforce.

Example:
text
Copy code
MILLISECOND(NOW())

13. MINUTE(datetime)

● Description: Returns the minute (0–59) from a Date/Time value.

Example:
text
Copy code
MINUTE(NOW())

14. MONTH(date)

● Description: Returns the month (1–12) from a date.


● Use Case: Extract month for validations or reports.

Example:
text
Copy code
MONTH(TODAY())

15. NOW()

● Description: Returns the current Date/Time value.


● Use Case: Time-sensitive validations or calculations.

Example:
text
Copy code
NOW()

● Returns the current date and time.

16. SECOND(datetime)
● Description: Returns the second (0–59) from a Date/Time value.

Example:
text
Copy code
SECOND(NOW())

17. TIMENOW()

● Description: Returns the current time without the date.


● Use Case: Compare or validate time-only values.

Example:
text
Copy code
TIMENOW()

18. TIMEVALUE(expression)

● Description: Converts a Date/Time or text expression to a Time value.


● Use Case: Extract the time portion of a Date/Time field.

Example:
text
Copy code
TIMEVALUE("2025-01-01 14:30:00")

19. TODAY()

● Description: Returns the current date without time.


● Use Case: Date-only validations or reports.

Example:
text
Copy code
TODAY()


20. UNIXTIMESTAMP(datetime)

● Description: Returns the UNIX timestamp (in seconds) of a Date/Time value.


● Use Case: Convert Salesforce dates to epoch time.

Example:
text
Copy code
UNIXTIMESTAMP(NOW())

21. WEEKDAY(date)

● Description: Returns the day of the week (1 for Sunday, 7 for Saturday).
● Use Case: Validate weekdays for business logic.

Example:
text
Copy code
WEEKDAY(TODAY())

22. YEAR(date)

● Description: Returns the year from a date.


● Use Case: Extract the year for validation or reporting.

Example:
text
Copy code
YEAR(TODAY())

Summary Table
Function Description Example Result
ADDMONTHS Adds months to a date ADDMONTHS(TODAY() Adds 3 months
, 3) to today

DATE Creates a date from DATE(2025, 1, 1) Jan 1, 2025


year, month, and day

DATETIMEVALUE Converts text to DATETIMEVALUE("20 Jan 1, 2025


Date/Time 25-01-01")

DATEVALUE Extracts date from DATEVALUE(NOW()) Current date


Date/Time

DAY Returns day of the DAY(TODAY()) e.g., 6


month

DAYOFYEAR Returns day of the year DAYOFYEAR(TODAY() e.g., 6


) (January 6)

HOUR Extracts the hour HOUR(NOW()) Current hour


(0-23)

ISOWEEK ISO week number ISOWEEK(TODAY()) Week of the


year (ISO)

MONTH Extracts month MONTH(TODAY()) 1 for January

NOW Current Date/Time NOW() Current


timestamp

TODAY Current date TODAY() Current date


only

WEEKDAY Day of the week WEEKDAY(TODAY()) 1 (Sunday) to


7

#. Advanced Functions

1. CURRENCYRATE(ISO_code)

● Description: Retrieves the conversion rate for the specified ISO currency code,
based on the corporate currency.
● Use Case: Calculate amounts in different currencies in a multi-currency organization.

Example:
text
Copy code
CURRENCYRATE("USD")

● Returns the conversion rate for USD.


● Important Notes:
○ Only available in organizations with multi-currency enabled.
○ Use this to dynamically convert amounts in formulas based on the current
exchange rate.

2. ISCHANGED(field)

● Description: Returns TRUE if a field value is changed during a record update.


● Use Case: Validate or trigger logic based on whether a field's value was modified.

Example:
text
Copy code
ISCHANGED(Account.Name)

● Returns TRUE if the Account Name is changed in the current operation.


● Important Notes:
○ Commonly used in validation rules, workflow rules, and triggers to enforce
business rules.
○ It only works during record updates, not during record creation.

3. REGEX(text, regex_pattern)

● Description: Compares a text field against a regular expression (regex) pattern.


Returns TRUE if the text matches the pattern.
● Use Case: Validate text input, such as email addresses, phone numbers, or custom
formats.

Example:
text
Copy code
REGEX(Email, "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$")

● Returns TRUE if the Email field contains a valid email address.


● Additional Examples:
Validate a 10-digit phone number:
text
Copy code
REGEX(Phone, "^\\d{10}$")

Validate a postal code:


text
Copy code
REGEX(Postal_Code__c, "^\\d{5}(-\\d{4})?$")


● Important Notes:
○ Regular expressions can be complex but are powerful for enforcing specific
text formats.
○ Test your regex patterns thoroughly to avoid unintended rejections or
matches.

4. VLOOKUP(field_to_return, field_on_lookup_object, lookup_value)

● Description: Searches for a value in a custom object and returns a related field's
value if a match is found.
● Use Case: Cross-reference data between related objects in formulas.

Example:
Suppose you have a custom object Exchange_Rates__c with fields Currency_Code__c
and Rate__c. To retrieve the rate for a specific currency:
text
Copy code
VLOOKUP(Rate__c, Currency_Code__c, "USD")

● Returns the exchange rate for USD from the Exchange_Rates__c object.
● Important Notes:
○ Only works with custom objects.
○ The field_on_lookup_object must be an external ID or unique field.
○ If no match is found, the function returns NULL.

Summary Table
Function Description Example

CURRENCYRATE Retrieves the exchange rate CURRENCYRATE("USD")


for a specific currency.
ISCHANGED Checks if a field value has ISCHANGED(Account.Name)
changed during an update.

REGEX Validates text input against a REGEX(Email,


regular expression pattern. "^[A-Za-z0-9._%+-]+@[A-Za-z
0-9.-]+\\.[A-Za-z]{2,}$")

VLOOKUP Cross-references a field VLOOKUP(Rate__c,


value from a custom object Currency_Code__c, "USD")
and returns related data.

You might also like