Salesforce ISNUMBER Function

In this Salesforce tutorial, we will learn about the Salesforce ISNUMBER function with its use cases, syntax, and practical examples. The ISNUMBER function is executable in the formulas and validation rules of Salesforce Lightning and Salesforce Classic.

What is ISNUMBER Function in Salesforce

In Salesforce, the ISNUMBER function is a formula function that is used to determine whether a given expression or field contains a numeric value. This function returns a Boolean value true and false, based on whether the specific value is a number.

This function is executable in various scenarios like when you have to identify whether a field contains a numeric value or not, then you can use this function to create a validation rule.

Syntax for ISNUMBER function in Salesforce

The basic syntax of the ISNUMBER function is as follows:

ISNUMBER(expression)

The expression in the above syntax is the value or field that you want to check for being a number.

Considerations:

There are a few considerations that we should be aware of while using the ISNUMBER function for formula fields and validation rules.

  • If the field value is left blank then the function returns FALSE.
  • The field input including languages and special characters including a space returns False.
  • The ISNUMBER function returns TRUE for scientific formatting such as “3BD”.

Use the ISNUMBER function in Salesforce Lightning

In this example, we will create a validation rule in the Opportunites object using the ISNUMBER function. This validation rule will ensure that the custom field Tracking Number only contains a numeric value and only takes input like 12060 instead of 120UID.

This validation rule will give an error if the field is entered with any values other than numerical.

Now follow the below steps, to create a Validation rule in Salesforce Lightning.

1. Navigate to the Setup page of Salesforce Lightning and for that click on the Settings icon and in the dropdown select the Setup option.

2. In the Setup window of Lightning, click on the Object Manager tab.

3. From the list of objects in the Object Manager select the Opportunities object.

4. In the setup of the Opportunity object, go to the left sidebar and select Validation Rules then in the next window click on the New button.

Salesforce Lightning ISNUMBER function

5. In the field Rule Name enter a relevant name for the validation rule. In this example, I have labeled the validation rule as Tracking Number Validation.

Define a Validation rule using ISNUMBER function in Salesforce

6. In the section Error Condition Formula, enter the below formula in the formula editor.

AND(
  NOT(ISBLANK( TrackingNumber__c )),
  NOT(ISNUMBER( TrackingNumber__c ))
)
  • The AND function returns true only if all specified conditions in the formula are true.
  • NOT(ISBLANK( TrackingNumber__c )), checks if the “TrackingNumber__c” field is not blank.
  • NOT(ISNUMBER( TrackingNumber__c )), ensures that the value in the “TrackingNumber__c” field is a numeric value.

7. After entering the formula, click on the button Check Syntax to check the error in the formula.

Salesforce Lightning ISNUMBER function Validation rule

8. In the field Error Message define the message that will appear when the defined Validation rule is true. In this example, I have entered the error message Use the numerical only to enter this field.

At last click on the Save button to save the validation rule in the object.

ISNUMBER use case in Salesforce Lightning

Now open the Opportunity record to check whether this validation rule returns an error when the conditions are not True.

Now we will enter the field for which we have created the validation rule.

Salesforce create a validation rule using the ISNUMBER function

As we can see in the above image, when we entered a value other than numerical the condition for the validation rule became true and the error was displayed on the screen.

In this way, we have successfully executed the ISNUMBER function in Salesforce Lightning by creating a custom validation rule.

Use the ISNUMBER function in Salesforce Classic

In this example, we will create a validation rule using the ISNUMBER function. This validation rule will check if the Account field Account code is written in numerical. If any other input is entered in this field other than numerical, an error message will appear on the screen.

1. On the Home page of Salesforce Classic, click on the Setup tab that is on the upper side of the window.

2. In the Setup window, go to the Build section in the left sidebar and select Customize -> Account -> Validation Rules.

Salesforce Classic Validation rule with ISNUMBER function

3. In this window, click on the New button to create a validation rule.

4. In this step, enter a relevant name for the validation rule according to your requirements.

In this example, I have named this validation rule Account code Validation and after this write the description for the validation rule (optional).

Validation rule in Salesforce Classic using the ISNUMBER function

5. Now enter the below formula to define the condition of the validation rule.


AND(
  NOT(ISBLANK(Account_Code__c)),         
  NOT(ISNUMBER(VALUE(Account_Code__c)))  
)

The conditions defined in the above formula are as follows.

  • The AND function will check if both conditions are true in the formula.
  • NOT(ISBLANK(Account_Code__c)), checks if the field Account.
  • NOT(ISNUMBER(VALUE(Account_Code__c))), evaluates true if the input in the field Account code is not a number.

6. After entering the formula click on the button Check syntax to validate the formula.

Validation rule in Salesforce classic using ISNUMBER function

7. On successful validation, go to the section Error Message on the same screen, and in the field Error Message enter the message that will appear on the screen when the validation rule condition is true.

After entering the message click on the Save button.

Salesforce Classic Validation rule using ISNUMBER function

As we click on the Save button the validation rule will be created in the Account object.

Now we will open a record in the Account object to check whether the validation rule created for the field Account Code is working or not.

Salesforce create a validation rule using the ISNUMBER function in Classic

As we can see in the above image when we enter the alphabetical values in the field Account Code, an error message is displayed on the screen because according to the condition defined in the validation rule, we can only enter numerals in this field.

In this way, we successfully executed the ISNUMBER function in Salesforce Classic by creating a custom Validation rule with the ISNUMBER function.

Conclusion

In this Salesforce tutorial, we have learned about the ISNUMBER function, and with the help of the above examples, we have created validation rules with the ISNUMBER function in Salesforce Lightning and Salesforce Classic.

Along with this we also learned about the use cases and syntax of the ISNUMBER function. We also discussed the considerations that we should be aware of while using the ISNUMBER function in Salesforce.

You may like to read: