Untitled Document
Untitled Document
Logical
1. Logical Functions
1. BLANKVALUE(expression, substitute_value)
Example:
text
Copy code
BLANKVALUE(Phone, "No Phone Provided")
2. ISBLANK(expression)
Example:
text
Copy code
ISBLANK(Email)
3. 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)
5. ISNULL(expression)
Example:
text
Copy code
ISNULL(Amount)
6. ISNUMBER(text)
Example:
text
Copy code
ISNUMBER(AccountNumber)
● Ensures that AccountNumber contains only numeric characters.
7. NULLVALUE(expression, substitute_value)
Example:
text
Copy code
NULLVALUE(Phone, "Unknown")
8. PRIORVALUE(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()
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)
Example:
text
Copy code
BEGINS(Name, "A")
2. CONTAINS(text, compare_text)
Example:
text
Copy code
CONTAINS(Email, "@")
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")
4. TEXT(field)
Example:
text
Copy code
TEXT(Amount)
5. INCLUDES(multi-select_picklist, value)
Example:
text
Copy code
INCLUDES(Regions, "North")
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")
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)
Example:
text
Copy code
CASESAFEID(Id)
9. CHR(number)
Example:
text
Copy code
CHR(65)
● Returns "A".
Example:
text
Copy code
FIND("@", Email, 1)
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)
Example:
text
Copy code
INITCAP("salesforce formula")
Example:
text
Copy code
LEFT(Name, 3)
14. LEN(text)
Example:
text
Copy code
LEN(Phone)
15. LOWER(text)
Example:
text
Copy code
LOWER("SALESFORCE")
● Returns "salesforce".
Example:
text
Copy code
LPAD("123", 5, "0")
● Returns "00123".
17. MID(text, start_num, num_chars)
Example:
text
Copy code
MID(Name, 2, 3)
18. PICKLISTCOUNT(multi-select_picklist)
Example:
text
Copy code
PICKLISTCOUNT(Regions)
19. REVERSE(text)
Example:
text
Copy code
REVERSE("Salesforce")
● Returns "ecrofelasS".
Example:
text
Copy code
RPAD("123", 5, "0")
● Returns "12300".
Example:
text
Copy code
SUBSTITUTE(Phone, "-", "")
23. TRIM(text)
Example:
text
Copy code
TRIM(" Hello ")
● Returns "Hello".
24. UPPER(text)
Example:
text
Copy code
UPPER("salesforce")
25. VALUE(text)
Example:
text
Copy code
VALUE("123")
● Returns 123.
#. Math Functions
1. ABS(number)
Example:
text
Copy code
ABS(-5)
● Returns 5.
2. ACOS(number)
Example:
text
Copy code
ACOS(0.5)
3. ASIN(number)
Example:
text
Copy code
ASIN(0.5)
4. ATAN(number)
Example:
text
Copy code
ATAN(1)
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)
6. CEILING(number)
Example:
text
Copy code
CEILING(4.2)
● Returns 5.
7. COS(number)
Example:
text
Copy code
COS(PI())
● Returns -1.
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)
Example:
text
Copy code
EXP(1)
● Returns 2.718.
10. FLOOR(number)
Example:
text
Copy code
FLOOR(4.8)
● Returns 4.
Example:
text
Copy code
GEOLOCATION(37.7749, -122.4194)
12. LN(number)
Example:
text
Copy code
LN(10)
● Returns 2.302.
Example:
text
Copy code
LOG(100, 10)
● Returns 2.
Example:
text
Copy code
MAX(10, 20, 5)
● Returns 20.
Example:
text
Copy code
MIN(10, 20, 5)
● Returns 5.
Example:
text
Copy code
MOD(10, 3)
● Returns 1.
17. PI()
Example:
text
Copy code
PI()
● Returns 3.14159.
Example:
text
Copy code
ROUND(4.567, 2)
● Returns 4.57.
19. SIN(number)
Example:
text
Copy code
SIN(PI()/2)
● Returns 1.
20. TAN(number)
Example:
text
Copy code
TAN(PI()/4)
● Returns 1.
Example:
text
Copy code
TRUNC(4.567, 2)
● Returns 4.56.
Summary Table
Function Description Example Result
1. ADDMONTHS(date, num_months)
Example:
text
Copy code
ADDMONTHS(TODAY(), 3)
● 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)
3. DATETIMEVALUE(expression)
Example:
text
Copy code
DATETIMEVALUE("2025-01-01 14:30:00")
4. DATEVALUE(expression)
Example:
text
Copy code
DATEVALUE(DATETIMEVALUE("2025-01-01 14:30:00"))
5. DAY(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)
Example:
text
Copy code
FORMATDURATION(3605)
● Returns 1:00:05.
8. FROMUNIXTIME(timestamp_in_seconds)
Example:
text
Copy code
FROMUNIXTIME(1672531200)
Example:
text
Copy code
HOUR(NOW())
10. ISOWEEK(date)
Example:
text
Copy code
ISOWEEK(TODAY())
11. ISOYEAR(date)
Example:
text
Copy code
ISOYEAR(TODAY())
12. MILLISECOND(datetime)
Example:
text
Copy code
MILLISECOND(NOW())
13. MINUTE(datetime)
Example:
text
Copy code
MINUTE(NOW())
14. MONTH(date)
Example:
text
Copy code
MONTH(TODAY())
15. NOW()
Example:
text
Copy code
NOW()
16. SECOND(datetime)
● Description: Returns the second (0–59) from a Date/Time value.
Example:
text
Copy code
SECOND(NOW())
17. TIMENOW()
Example:
text
Copy code
TIMENOW()
18. TIMEVALUE(expression)
Example:
text
Copy code
TIMEVALUE("2025-01-01 14:30:00")
19. TODAY()
Example:
text
Copy code
TODAY()
●
20. UNIXTIMESTAMP(datetime)
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)
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
#. 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")
2. ISCHANGED(field)
Example:
text
Copy code
ISCHANGED(Account.Name)
3. REGEX(text, regex_pattern)
Example:
text
Copy code
REGEX(Email, "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$")
○
● 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.
● 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