Skip to main content

Validating Fields on Forms

Frontend validations is a part of the InCountry Data Residency for Salesforce package. The package utilizes native Salesforce validation rules and use them to validate data inputs against the specified criteria. The InCountry Data Residency for Salesforce package pulls the error condition formulas from native validation rules and re-uses them to validate input data at the frontend side.

Setting up validation rules

For the details on how to create and configure validation rules, please check Salesforce documentation.

note

You need to disable a native validation rule if you migrate it to InCountry frontend validations. Due to usage of hash function, native validation rules may work incorrectly or throw an error due to replacement of clear-text values with their hashes.

note

When using frontend validations in Experience Cloud, ensure that the Validation_Rule__c object has the Public Read permission for the Default External Access in the sharing settings.

Synchronizing and activating frontend validations

  1. In the App Launcher form, select InCountry.

  2. Select Settings.

  3. Select the Salesforce object for which you want to synchronize the created validation rule.

  4. Expand the Frontend Validations section.

    Synchronize

  5. Click the down arrow icon on the rule you want to synchronize to expand the list of actions within it.

  6. Click Synchronize.

  7. Click Activate.

Activate

Once the synchronization of the validation rule and activation of a frontend validation are complete, the following validation will be applied to the record create/edit operation when you submit the form.

You save a new or modified record, the assigned frontend validations will be executed. They will use the error condition formula to verify the input values against specific criteria. If validation fails, you will see a corresponding error message. If validation passes, a record will be saved successfully.

Error message

Supported system objects

The following system objects are supported/not supported in the Error Condition Formula text box:

ObjectSupportedField restrictions
$UserThe 'LanguageLocaleKey', 'LocaleSidKey', 'TimeZoneSidKey' fields should be populated as key values in the error condition formula. Standard Salesforce validation rules can support both 'en_US', and 'English', but since the field values are retrieved through a SOQL query, the only value returned is the key value 'en_US' and we can use only this value.

The 'StartDay' and 'EndDay'fields are not supported by the rules since it is not possible to obtain values for these fields through a SOQL query. This is a Salesforce limitation.
$UserRole-
$Organization-
$Profile-
$CustomMetadata-
$Label-
$ObjectType-
$System-
$Setup-

Supported formula functions

FunctionsDescription

DATE & TIME

ADDMONTHS(date,num)

Returns the date that is the indicated number of months before or after a specified date. If the specified date is the last day of the month, the resulting date is the last day of the resulting month. Otherwise, the result has the same date component as the specified date.

DATE(year,month,day)

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.

DATETIMEVALUE(expression)

Returns a year, month, day, and GMT time value.

DATEVALUE(expression)

Returns a date value for a date/time or text expression.

DAY(date)

Returns a day of the month in the form of a number from 1 through 31.

HOUR(expression)

Returns the local time hour value without the date in the form of a number from 1 through 24.

MILLISECOND(expression)

Returns a value in milliseconds in the form of a number from 0 through 999.

MINUTE(expression)

Returns a value in minutes in the form of a number from 0 through 60.

MONTH(date)

Returns the month, a number between 1 (January) and 12 (December) in the numeric format of a given date.

NOW()

Returns a date/time representing the current moment.

SECOND(expression)

Returns a value in seconds 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(expression)

Returns the local time value without the date, such as business hours.

TODAY()

Returns the current date as a date data type.

WEEKDAY(date)

Returns the day of the week for the given date, using 1 for Sunday, 2 for Monday, through 7 for Saturday.

YEAR(date)

Returns the four-digit year in number format of a given date.

LOGICAL

AND(logical1,logical2,...)

Returns a TRUE response if all values are true; returns a FALSE response if one or more values are false.

BLANKVALUE(expression, substitute_expression)

Determines if an expression has a value and returns a substitute expression if it doesn’t. If the expression has a value, returns the value of the expression.

CASE(expression, value1, result1, value2, result2,...,else_result)

Checks a given expression against a series of values. If the expression is equal to a value, returns the corresponding result. If it isn't equal to any values, it returns the else_result value.

IF(logical_test, value_if_true, value_if_false)

Determines if expressions are true or false. Returns a given value if true and another value if false.

ISBLANK(expression)

Determines if an expression has a value and returns TRUE if it doesn't. If it contains a value, this function 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, this function returns FALSE.

ISNULL(expression)

Determines if an expression is null (blank) and returns TRUE if it is. If it contains a value, this function returns FALSE.

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 need to change any existing formulas.

ISNUMBER(Text)

Determines if a text value is a number and returns TRUE if it is. Otherwise, it returns FALSE.

NOT(logical)

Returns FALSE for TRUE and TRUE for FALSE.

NULLVALUE(expression, substitute_expression)

Determines if an expression is null (blank) and returns a substitute expression if it is. If the expression isn’t blank, returns the value of the expression.

Use BLANKVALUE instead of NULLVALUE in new formulas. BLANKVALUE has the same functionality as NULLVALUE, but also supports text fields. Salesforce continues to support NULLVALUE, so you don't need to change existing formulas.

OR(logical1,logical2,...)

Determines if expressions are true or false. Returns TRUE if any expression is true. Returns FALSE if all expressions are false.

PRIORVALUE(field)

Returns the previous value of a field.

MATH

ABS(number)

Calculates the absolute value of a number. The absolute value of a number is the number without its positive or negative sign.

CEILING(number)

Rounds a number up to the nearest integer, away from zero if negative.

EXP(number)

Returns a value for e raised to the power of a number you specify.

FLOOR(number)

Returns a number rounded down to the nearest integer, towards zero if negative.

LN(number)

Returns the natural logarithm of a specified number. Natural logarithms are based on the constant e value of 2.71828182845904.

LOG(number)

Returns the base 10 logarithm of a number.

MAX(number,number,...)

Returns the highest number from a list of numbers.

MCEILING(number)

Rounds a number up to the nearest integer, towards zero if negative.

MFLOOR(number)

Rounds a number down to the nearest integer, away from zero if negative.

MIN(number,number,...)

Returns the lowest number from a list of numbers.

MOD(number,divisor)

Returns a remainder after a number is divided by a specified divisor.

ROUND(number,num_digits)

Returns the nearest number to a number you specify, constraining the new number by a specified number of digits.

SQRT(number)

Returns the positive square root of a given number.

TEXT

BEGINS(text, compare_text)

Determines if text begins with specific characters and returns TRUE if it does. Returns FALSE if it doesn't.

CASESAFEID(id)

Converts a 15-character ID into a case insensitive 18-character ID.

CONTAINS(text, compare_text)

Compares two arguments of text and returns TRUE if the first argument contains the second argument. If not, returns FALSE.

FIND(search_text, text [, start_num])

Returns the position of a string within a string of text represented as a number.

INCLUDES(multiselect_picklist_field, text_literal)

Determines if any value selected in a multi-select picklist field equals a text literal you specify.

ISPICKVAL(picklist_field, text_literal)

Determines if any value selected in a multi-select picklist field equals a text literal you specify.

LEFT(text, num_chars)

Returns the specified number of characters from the beginning of a text string.

LEN(text)

Returns the number of characters in a specified text string.

LOWER(text)

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(text, padded_length [, pad_string])

Inserts characters you specify to the left-side of a text string.

MID(text, start_num, num_chars)

Returns the specified number of characters from the middle of a text string given the starting position.

RIGHT(text, num_chars)

Returns the specified number of characters from the end of a text string.

RPAD(text, padded_length [, pad_string])

Appends characters to the right side of a text string.

SUBSTITUTE(text, old_text, new_text)

Substitutes old text with new text in a text string.

TEXT(value)

Converts a percent, number, date, date/time, or currency type field into text wherever 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(text)

Removes the spaces and tabs from the beginning and end of a text string.

UPPER(text)

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.

VALUE(text)

Converts a text string to a number.

ADVANCED

ISCHANGED(field)

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.

REGEX(Text, RegEx_Text)

Compares a text field to a regular expression and returns TRUE if there's a match. Otherwise, it returns FALSE.

All the single quotes must be escaped. The correct way of escaping single quotes: REGEX(Name, "^[a-zA-Z\\-\\.\\\' ]*$" )

Management of frontend validations

IconDescriptionAvailable actions

The Salesforce validation rule is found but not synchronized with InCountry frontend validations.

You can only synchronize the record or edit it. The edit action leads to the original Salesforce rule.

The Salesforce validation rule is synchronized with InCountry frontend validations and up to date with the Salesforce rule.

You can use the buttons activate, deactivate, delete (It affects only synchronized rules, activation/deactivation or deletion of synchronized rules has no effect on Salesforce validation rules). The edit action leads to the Salesforce rule.

This means that the original Salesforce validation rule was updated after the rule was synchronized with the InCountry frontend validation.

You can perform all actions on the synchronized rule and re-synchronize the rule to make it up to date with the InCountry frontend validation.

  • If the original Salesforce validation rule is deleted, you cannot edit the rule, only activate/deactivate/delete.

  • If you delete a synchronized frontend validation, the original validation rule will be shown in place of the deleted one. The synchronization status is displayed as unsynchronized. You can synchronize it again.