Salesforce ISNEW Function

The Salesforce ISNEW function is used to check whether a record is being created for the first time or is being updated by the Salesforce user.

The Salesforce ISNEW function is a very common topic when we are dealing with the Salesforce validation rules, but sadly, there is no online tutorial available that provides us with complete information with the example.

As a Salesforce Administrator, I am writing a complete blog post that will guide you on the topic of the ISNEW function in Salesforce with its syntax, considerations, use case, etc.

Moreover, I am going to explain step-by-step how to use the ISNEW function in Salesforce Lightning and Salesforce Classic with real business example scenarios.

Salesforce ISNEW Function

What is the ISNEW Function in Salesforce?

The ISNEW function in Salesforce is one of the Salesforce Logical functions that is used to work on conditional statements and ensure data integrity.

It is a function that is used to determine whether a record is being created for the first time or not. It evaluates the result to TRUE if the record is new, but if an existing record is being updated, this function returns FALSE.

Where can we use the ISNEW function in Salesforce?

The ISNEW function is available in the validation rules in Salesforce. We can’t use the functionality of the function in the formula fields.

Additionally, we can use it where we want to execute specific validation during the record creation process.

How can we write the ISNEW function in Salesforce?

The syntax of the ISNEW function in Salesforce is given below. It is important to note that the function takes no parameter.

ISNEW()

Are there any considerations that we must take care of while working with the ISNEW function in Salesforce?

Yes, there are various considerations that we must take care of while working with the Salesforce ISNEW function. The considerations are given below:

  • The ISNEW function can be used in validation rules, field updates, workflow rules, assignment rules, and processes.
  • We can use the NOT function to reverse the return values of the ISNEW function. Example: If the ISNEW function returns TRUE, it means that the record is being created, then NOT(ISNEW()) would return FALSE, and vice versa.
  • In Salesforce, the record would not be regarded as a new record when it’s evaluated with respect to the time-based trigger. It means that if the ISNEW function is used in a workflow rule that has a time-based trigger, it will always return FALSE.
  • If the ISNEW function is used in a field update that is associated with an approval action, it will always return FALSE because records involved in an approval process have a unique lifecycle, and the concept of being new does not apply to approval action.

With this, we have learned about the ISNEW function with its syntax, use cases, and considerations.

How to use the ISNEW function in Salesforce Lightning

The following are the steps to use the ISNEW function in the validation rule in Salesforce Lightning. Let’s take a scenario and try to understand the concept.

Suppose we want to make sure that account number and employee are provided when a new account is added to Salesforce. The steps are as follows:

1. Login into the Salesforce account in Lightning Interface.

Move your course over the “Gear” icon on the right side of the screen, click it, and choose “Setup” (Setup for the current app) from the dropdown menu, if not on the “Home Setup” page.

Salesforce ISNEW Function

2. Find the “Object Manager” option in the navigation bar and click it. Search for the object on which we want to use the ISNEW function in the “Quick Find” box.

See also  COS() Function in Salesforce | Calculate cosine value in Salesforce

As per the scenario, we need the “Account” object, so search it and click once found.

Salesforce ISNEW Function Example

3. Scroll down to the bottom of the page and click on “Validation Rules” from the menu on the left side of the screen.

The validation rules page opens on the right side of the page; now click on the “New” button given at the top right side.

Salesforce Lightning ISNEW Function

4. Enter the “Rule Name” and “Description” according to your requirements. As per the scenario, let’s suppose we enter the rule name as “New Account Creation Validation Rule”.

Next, check the “Active” checkbox to activate and use this validation rule in Salesforce.

Salesforce Lightning ISNEW Function Example

5. In this step, enter the formula expression. If this formula expression is true, display the text defined in the Error Message area.

As per the scenario, we need to ensure that essential information, such as employee and account number fields, is provided when a new account is created in Salesforce.

For this, we need the “ISNEW” function, so move to the left side towards the Functions, and from the “All Function Categories” dropdown, choose the category that includes the required function.

So, next, click on the “Logical” category, and from the list of the functions, trace the function we need and select it.  After that, click on the “Insert Selected Function” button.

The function has been successfully added to the box; in accordance with the validation rule, replace the parameter with the expression. Use the “Insert Field” button to enter the field and the “Insert Operator” menu button to enter the operators.

The formula for this scenario is as follows:

AND(
    ISNEW(), 
    ISBLANK( NumberOfEmployees ), 
    ISBLANK( AccountNumber )
)

A detailed description is given below:

  • AND Function: The AND function is used as we want to combine multiple conditions. The function returns TRUE only if all of the specified conditions are true. If any one of the conditions is false, the function returns FALSE.
  • ISNEW Function: The ISNEW function is used to check if a record is newly inserted; it returns TRUE if the formula is evaluated during the creation of a new record. Otherwise, it returns FALSE.
  • ISBLANK Function: The ISBLANK function is used to check whether the specified fields are blank or empty.

The formula evaluates to TRUE only if all of the following conditions are met:

  • The record is being created (new record).
  • The Employee field is blank.
  • The Account Number is blank.

To ensure that the formula is error-free after inputting the error condition formula, click the “Check Syntax” button. Proceed to the next section as soon as we receive the success message: “No errors found”.

ISNEW Function in Salesforce

6. It’s time to define the box’s “Error Message” at this point. When the Error Condition formula is true, this message will show.

According to our situation, the error notice will appear if the employee and account number fields are left blank while creating a new record.

Let’s suppose we enter the message as given below:

Account Number and Employee must not be blank during record creation.

Now, the error message’s location can then be specified by selecting “Enter Location”. This error notification may show up at the top of the page or just below one of the page’s fields.

Note: The error message appears at the top of the page if there are multiple error messages. If not, your error message appears next to the field that has to be selected by the user.

See also  ABS() Function in Salesforce | Calculate absolute value in Salesforce

7. Click on the “Save” button to successfully save your validation rule in the account object in Salesforce Lightning.

ISNEW Function in Salesforce Example

8. Once the validation rule is created, we can use the formula field and check whether it works or not.

  • Open the “Account” object, create the new account with the necessary fields, and save it.
  • Once you save, if the “Account Number” and “Employees” fields are not blank, the record is created successfully; otherwise, it shows you an error as the specified location.

Let’s deeply understand it with the example:

  • Suppse you have created a new account with the account number “AC489GR”, employees “30” and save it. The validation rule executes and finds that the fields are not blank and the record is newly created.
  • Therefore, records are successfully created without any errors or security restriction issues.
ISNEW Function in Salesforce Lightning

With this, we have learned how to use the ISNEW function in the Salesforce Lightning function.

What is use of ISNEW function in Validation Rules in Salesforce Classic

There are various scenarios where we can use the ISNEW function in Salesforce, and one of them is that we want to create a validation rule that works when the status is pending and approver or approval notes may not specified.

The following are the steps to use the ISNEW function in the validation rule in the Salesforce Classic.

1. Sign in to the Salesforce account as an administrator in the Classic Interface. Then, click on the “Setup” option located at the top right side of the page and move to the classic setup.

ISNEW Function in Salesforce Classic

2. Moved down to the “Build” section on the left side of the page. Click on the “Customize” dropdown; here, we will get the list of all objects to choose the object on which we want the desired function.

Now, expand the option and click on the “Validation Rules” from the menu on the left side of the screen.

ISNEW Function in Salesforce Classic Example

3. Now, click on the “New” button from the “Validation Rules” section, which is used to define one or more validation rules that consist of an error condition and corresponding error message.

Salesforce Classic ISNEW Function

4. Firstly, define the “Validation Rule Edit”. Type the “Rule Name” as per the requirement, and if we want, we can also define the “Description” for the validation rule.

Make sure that the “Active” checkbox is always checked if we want to make it in use.

According to the scenario, we can enter the field label “Contract Approval Conditions”.

Salesforce Classic ISNEW Function Example

5. Secondly, in the formula editor, enter the formula we want to use. If this formula expression is true, display the text defined in the error message area.

According to the scenario, we need to create a validation rule that works when the status is pending and the approver or approval notes field may not specified.

To create the formula, click on the “All Functions Categories” dropdown and choose the required function category. Following the scenario, we need to select the “Logical” category.

Search for the “ISNEW” function and click on it. Then, click on the “Insert Selected Function” button under the functions section.

After that, replace the parameters of the functions with the functions, fields, or operators and formula according to the scenario. The formula is as given below:

AND(ISNEW(), 
    ISPICKVAL(Approval_Status__c, 'Pending Approval'), 
    OR(ISBLANK(Contract_Approver__c),
    ISBLANK(Approval_Notes__c))
)

Here is a detailed explanation of the formula:

  • AND Function: The AND function is used to combine multiple expressions. It returns TRUE if all the specified expressions are true. If any one of the expressions is false, the entire expression evaluates to FALSE.
  • ISNEW() Function: The ISNEW function is used to check whether the record is created new; if it is, the function returns TRUE, and if the record is being updated, the function returns FALSE.
  • ISPICKVAL(Approval_Status__c, ‘Pending Approval’): The ISPICKVAL function is used to check whether the “Approval Status” field has a picklist value equal to ‘Pending Approval’. If it is, it returns TRUE and moves to the next conditions, but if it is FALSE, the formula stops working here.
  • OR(ISBLANK(Contract_Approver__c), ISBLANK(Approval_Notes__c)): The OR function is used to check if either the “Contract Approver” field or the “Approval Notes” field is blank.
  • ISBLANK(Contract_Approver__c): The ISBLANK function returns TRUE if the Contract Approver field is blank.
  • ISBLANK(Approval_Notes__c): The ISBLANK function returns TRUE if the Approval Notes field is blank.

The formula evlaute to TRUE only under the following conditions:

  • The record is being created.
  • The Approval Status field has a picklist value equal to Pending Approval.
  • Either the Contract Approver field or the Approval Notes field (or both) is blank.

Click on the “Check Syntax” button to check the syntax of the formula you type. If there are any syntax errors, an error message will be displayed.

ISNEW Function in Salesforce Validation Rule

6. Below the formula, specify the error condition. This is the condition that, when true, triggers the error message.

See also  HYPERLINK() Function in Salesforce

As per your scenario, the error message will be displayed when the record is newly created, the status field is pending, and either the contract approver and approval note or both are blank.

According to the scenario, we can enter the error message as defined below:

Contract Approver and Approval Notes cannot both be blank during record creation with a status of 'Pending Approval'.

This error message can either appear at the top of the page or below a specific field on the page; we can specify the location by checking the radio button given next to options “Top of Page” and “Field” in “Enter Location”.

7. Click on the “Save” button to save the validation rule.

ISNEW Function in Salesforce Validation Rule Example

8. Once the validation rule is created, we can use the formula field and check how it works.

  • Open the “Contract” object, create a new contract with the necessary and mandatory fields, and save the contract.
  • Once you save, if the contract is created with the status field or approver and approval note field, the contract gets successfully created; otherwise, it shows the error defined in the validation rule.

Let’s deeply understand it with the example

  • Suppose we have to create a contract with the account name “Blues Entertainment Corp.”, status “Draft”, contract start date “1/16/2024”, contract (terms month) “5”, and approval status “Pending Approval” and save it.
  • The validation rule executes and finds that the record is newly begun created and approval status is pending, but the approver and approval notes fields are empty, so it generates an error message “Contract Approver and Approval Notes cannot both be blank during record creation with a status of ‘Pending Approval'”.
Example of ISNEW Function in Salesforce Classic

With this, we have learned the use of the ISNEW function in the Salesforce Classic validation rule with an example.

Conclusion

The Salesforce ISNEW function is a valuable tool for administrators and developers, which is used in validation rules. It is a logical function that works only on the newly created record.

We have learned in complete detail about the ISNEW function with its syntax, considerations, examples, and more. We have also learned to use the function in Salesforce Lightning and Salesforce Classic validation rules.

You may like to read: