ISCHANGED Function in Salesforce

The ISCHANGED function in Salesforce is used to check whether a specified field has been modified.

The Salesforce ISCHANGED function in Salesforce is one of the powerful functions of Salesforce that is used to manage and customize the data effectively.

As a Salesforce Administrator, I will explain to you the ISCHNAGED function with its syntax, use case, consideration, and more. I will also guide you step-by-step on how to use the ISCHANGED function in Salesforce Lightning and Salesforce Classic.

ISCHANGED Function in Salesforce

What is the ISCHANGED Function in Salesforce?

The ISCHANDED function in Salesforce is one of the Salesforce Advanced functions that is used to manage and track the fields and their updates in Salesforce org.

It is the function that is used to determine whether a specified field has been modified. The function compares the value of a field to the previous value, and if the values are different, the function returns TRUE, but if the values are the same, this function returns FALSE.

What is the syntax to write the ISCHANGED function in Salesforce?

The syntax of the ISCHANGED function is given below:

ISCHANGED(field)

field: The field parameter specifies the field you want to monitor for changes or the name of the field you want to compare.

Why ISCHANGED function not available while creating the formula field?

The Salesforce ISCHANGED function is not available while creating the formula field because you can not use the functionality of the function in the formula fields.

The function is available in Salesforce assignment rules that are used for assigning records based on defined criteria. It is also available in validation rules that evaluate whether a specified field has been modified.

Additionally, while configuring field updates, the ISCHANGED is commonly used to automate field updates. The function is available in workflow rules with the specified evaluation criteria.

Moreover, the ISCHANGED function is available in the formula criteria for executing actions in Process Builder.

When utilizing Salesforce’s ISCHANGED function, are there any anything we need to keep in mind?

Yes, there are a number of things to keep in mind while using the Salesforce ISCHANGED function. The considerations are given below:

If you use the NOT function in Salesforce, it reverses the logical value of a Boolean expression. It returns TRUE if the expression is FALSE, and vice versa.

The ISCHANGED function returns FALSE when evaluating any field on a newly created record.

The function returns TRUE when a text field was previously blank and now contains any value.

For the number, percent, or currency field, the ISCHANGED function returns TRUE in the following case:

  • When the number field was previously blank and now contains any value.
  • When the number field was previously zero and now is blank.
  • When the number field was previously zero and now contains any value other than zero.

With this, you have learned about the syntax, usage cases, and considerations of the ISCHANGED function in Salesforce.

How to use the ISCHANGED Function in Salesforce Lightning

Use the following steps to use the ISCHANGED function in Salesforce Lightning. Let’s clear it up with the help of a small scenario:

Scenario: You want to create the validation rule in Salesforce that checks on the contract term are changed, a future end date is provided, and if the status is not active raise an error.

See also  Salesforce TRIM Function

1. Log in to your Salesforce account as an administrator with your credentials. If you are not on the “Main Setup”, locate and click on the “Gear” icon in the top-right corner of the page to access the setup menu by choosing the “Setup” option from the dropdown.

2. On the main setup page, find and click on the “Object Manager” tab given at the navigation bar.

Now, select the Salesforce object for which you want to create the validation rule. According to the scenario, you need to choose the “Contract” object.

ISCHANGED Function in Salesforce

3. In this step, locate the “Validation Rules” tab in the left-hand menu within the selected object and click on it.

After that, click the “New” button to start the process of creating a new validation rule.

ISCHANGED Function in Salesforce Example

4. Define a validation rule by specifying the “Rule Name” and the “Description” for your validation rule.

As per the scenario, you can enter the rule name as “Contract Renewal Validation”. You can optionally set the description as “Rule Validate contract end date is greater than today’s date only when the contract is marked as Active”.

Make sure to check the “Active” checkbox to activate the validation rule. If this checkbox is not selected, the rule will not be enforced.

ISCHANGED Function in Salesforce Lightning

5. In the “Error Condition Formula” define the criteria that must be met for the validation rule to work. You can create the formula using Salesforce’s formula editor.

To enter the functions, click on “All Function Categories” in the functions section, then choose the desired category (in your case Advanced), after that, select the desired function (in your case ISCHANGED) and then click on the “Insert Selected Function”.

To enter the fields, click on the “Insert Field” button, choose the desired fields, and to enter the operators, click on the “Insert Operator” button and insert the needed operator.

For example, if you want to enforce any updates to the contract where the contract term is changed, the end date is set to a future date, and the status is not ‘Active,’ it gives you an error to make the status active to maintain data integrity.

The formula is as given below:

AND(
ISCHANGED( ContractTerm ),
EndDate > TODAY(),
NOT(ISPICKVAL(Status, 'Activated'))
)

A detailed description of the formula is given below:

  • ISCHANGED( ContractTerm): The ISCHANGED function checks if the ContractTerm field has been changed. If yes, proceed to the next AND condition.
  • EndDate > TODAY(): Here, you verify that the EndDate is set to a future date, ensuring that the contract end date is after the current date. The current date is calculated by the TODAY function.
  • NOT(ISPICKVAL(Status, ‘Activated’)): Here, you use the NOT function and ISPICKVAL function to ensure that the picklist field Status is not set to ‘Activated’.

The validation rule triggers an error if all the following conditions are TRUE:

  • The contract term has been changed.
  • The contract end date is set to a future date.
  • The contract status is not set to ‘Activated’.

After entering the formula, click on the “Check Syntax” button to verify that the formula is correct or has some errors.

ISCHANGED Function in Salesforce Lightning Example

6. In the “Error Message” section, enter a clear and informative error message that will be displayed to users when the validation rule is violated.

See also  Salesforce DATE Function

You can enter the error message as given below as per the scenario, it helps users understand why their record cannot be saved.

Contract status must be set to 'Active'.

Now, decide where you want the error message to appear. You can choose to display the error at the top of the page or at the location of the field by choosing the option from the checkbox.

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

ISCHANGED Function in Salesforce Validation Rule

8. Once the validation rule is created, you can check how it works.

  • Open the “Contracts” object, update the contract if needed, and save it.
  • If you update the contract term, the end date is greater than today, and the status is not set to activate, the validation error will arise.

Let’s deeply understand it with the example:

  • Suppose you have updated the contract term “5” and the close date of the contract is “12/25/2023”, today’s date “01/25/2024” where the end date is greater than today, but the contract status is set to draft.
  • As per the example defined above, the validation rule breaks down and gives the error “Contract status must be set to ‘Active'”. ‘
Salesforce Lightning ISCHANGED Function

With this, we have learned how to use the ISCHANGED function in Salesforce Lightning in the validation rule.

How to use the ISCHANGED Function in Validation Rule in Salesforce Classic

The following are the steps to use the ISCHANGED function in Salesforce Classic in Validation Rules. Let’s take an example and understand.

Example: You want to create a validation rule that will trigger if you change the lead status to closed – not converted and the description is not filled up.

1. Logging in to your Salesforce Classic account using the administrator credentials. Make sure that you are on the classic interface; if you are not on the classic interface, click on “Profile” and choose “Switch the Salesforce Classic”.

2. Locate and click on the “Setup” link found in the top right corner of the page.

Salesforce ISCHANGED Function

3. Find and click on the “Build” section on the left sidebar under the “Customize” dropdown, and you will see an object. Now, select the Salesforce object for which you want to create the validation rule.

According to the scenario, you need to select the “Leads” object.

Salesforce ISCHANGED Function Example

Within the selected object, you will find a “Validation Rules” link; click on it to navigate to the validation rules page.

4. To create a new validation rule, click on the “New” button. Here, you define a validation rule by specifying an error condition and a corresponding error message.

ISCHANGED Function in Salesforce Classic

5. Enter the “Rule Name” and “Description” in this section in accordance with your needs. Let’s say you enter “Lead Non Converted Validation” as the rule name.

Additionally, confirm that the “Active” checkbox is selected.

ISCHANGED Function in Salesforce Classic Example

6. In this step, enter the formula expression in this section. The text defined in the error message box should be displayed if this formula expression is true.

To create the validation rule formula, click on the “All Function Categories” -> select the “Function Category” -> choose the “Function” -> click on the “Insert Selected Function” button.

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

See also  Salesforce MONTH Function

According to the formula, the function is as given below:

AND(
ISCHANGED( Status ),
ISPICKVAL(Status, 'Closed - Not Converted'),
ISBLANK(Description)
)

Here is a detailed explanation of the formula:

  • ISCHANGED(Status): It is used to check if the Status field has been changed using the ISCHANGED function. If yes, the validation rule will proceed only.
  • ISPICKVAL(Status, ‘Closed – Not Converted’): It is used to check that the value of the Status field is ‘Closed – Not Converted’ using the ISPICKVAL function; if it is, a validation rule applies.
  • ISBLANK(Description): The ISBLABK function is used to verify that the Description field is blank if it is the validation rule trigger.

The provided validation rule will execute and give error when all of the following conditions are met:

  1. The Status field is changed.
  2. The new value of the Status field is set to ‘Closed – Not Converted’.
  3. The Description field is left blank.

To ensure that the formula is error-free, click the “Check Syntax” button. Proceed to the next section as soon as you receive the success message “No errors found”; if any error is there, you will receive an error message.

Salesforce Classic ISCHANGED Function

7. Enter a clear and understandable error message that users will see in the “Error Message” section when the validation rule is met. Users should understand why their records cannot be stored with the help of this message.

As per the scenario, you can enter the error message:

Description is mandatory when changing Lead Status to 'Closed - Not Converted'. Please provide a description explaining the reason.

Decide where you want the error message to appear. You can select options like “Top of Page” and “Field” based on your preference.

8. Click the “Save” button to save your validation rule.

Salesforce Classic ISCHANGED Function Example

9. Once the validation rule has been built, you can test how it works.

  • Open the “Leads” object, edit the record, and save the lead.
  • If you edit the lead status from any available option to the closed -not converted, then it produces an error depending upon the condition.

Let’s understand with an example:

  • Suppose you edit the “Ms Patricia Feager” lead, change its lead status from “Working – Contacted” to “Closed – Not Converted”, and have not filled out the description, and try to save the record.
  • It will produce an error because the Status field is changed to ‘Closed – Not Converted’ and the Description field is left blank.
Example of ISCHANGED Function in Salesforce

With this, you have learned how to use the ISCHANGED function in validation rules in Salesforce Classic, for example.

Conclusion

The ISCHANGED function in Salesforce is a tool that allows administrators to implement logic based on changes to specific fields. The whole article explains the ISCHANGED function with the syntax, use case, and considerations.

I have also explained in the article the step-by-step implementation of how to utilize the function in both Salesforce Lightning and Salesforce Classic in the validation rule.

You may like to read the following articles: