Salesforce ISOYEAR Function

In this Salesforce tutorial, you will learn the Salesforce ISOYEAR function. In addition, you will learn the syntax of the ISOYEAR function with various examples and use cases in Salesforce.

Do you want to get the year for a specific date according to the international standard for accurate date and time information in use cases of finance, logistics, and project management?

If yes, Salesforce provides us with the “ISOYEAR” function that can manipulate and extract information from date and time fields.

So, let’s proceed and explore the steps of using the ISOYEAR function in both Salesforce Lightning and Salesforce Classic with the help of real business-based scenarios.

Salesforce ISOYEAR Function

The Salesforce ISOYEAR() function is one of the date and time functions that can extract information from date and time fields. Salesforce ISOYEAR function returns the ISO 8601 week-numbering 4-digit year for the given date so that the first day is a Monday.

Here, the ISO 8601 Week-Numbering System is an international standard for representing dates and times. It is a system that defines the numbering weeks, where each week begins on a Monday and ends on a Sunday.

You all know that every country has its traditional week start day. For example in the United States week starts on Sunday, Europe week starts on Monday, Africa week starts on Saturday, etc.

So to deal with one system in different crucial use cases such as Financial Reporting, Employee Attendance and Work Hours, Customer Support and Service, Logistics, etc you can use ISOYEAR in Salesforce.

With this, you have understood the meaning and purpose of the ISOYEAR. Let’s move to the next section and take a look at the syntax of the ISOYEAR function in Salesforce

Syntax of ISOYEAR Function in Salesforce

The syntax for the ISOYEAR function is as given below:

ISOYEAR(date)

Here:

  • date: The date parameters take the date field or the date/time field for which you want to find ISO 8601 week-numbering year.

Return: The ISOYEAR function will return a 4-digit integer representing the year. So, you need to make sure that you select the number data type in the formula return type.

Now, you have learned to write the function in Salesforce. Let’s move to the next section and see some simple examples of the function that help you to understand the working of the ISOYEAR function in Salesforce.

ISOYEAR Function Examples in Salesforce

Below given table explains the working and the logic behind the ISOYEAR function in Salesforce.

Here, the “Input” column represents the date passed as the parameter in the function by the user, and the “Output” column represents the result returned by the ISOYEAR function in Salesforce.

Input/Date ExpressionOutput/Result
ISOYEAR(Due_Date__c). Suppose Due_Date__c is “06/12/2023” that is on Monday.2023 (As the entire week belongs to the same ISO year 2023).
ISOYEAR(Order_Date__c). Suppose Order_Date__c is “02/18/2024” that is on Sunday.2024 (As the entire week belongs to the same ISO year 2024).
ISOYEAR(Contract_End_Date__c). Suppose Contract_End_Date__c is “12/31/2024” that is on Tuesday.2025 (As the majority of the week is in the next ISO year 2025).
ISOYEAR(Project_Proposal_Date__c). Suppose Project_Proposal_Date__c is “12/31/2026” that is on Thursday.2026 (As the majority of the week is in the same ISO year 2026).
ISOYEAR(Expiry_Date__c). Suppose Expiry_Date__c is “12/31/2029” that is on Monday.2030 (As the majority of the week is in the next ISO year 2030).

With this, we have concluded that when the date is on the border between two calendar years and the majority of the week is in the next year, the ISOYEAR function will return the next year.

You have now learned simple examples that show you the logic behind the ISOYEAR function working. Let’s proceed to the next section and learn the step-by-step procedure of using the ISOYEAR function in Salesforce with a scenario-based example.

How to use ISOYEAR Function in Salesforce Lightning

Let’s discuss how to use the ISOYEAR function in the formula field with the help of the scenario that the sales team wants to determine the orders quarterly based on the fiscal year (Starts on Monday).

The following are the steps to use the ISOYEAR function in Salesforce Lightning as the per defined scenario:

1. Log into the Salesforce account as an admin in the Lightning Interface. If you are not on the main “Home Setup” page, click on the “Gear” icon on the right side, and from the dropdown select the “Setup” option.

Salesforce ISOYEAR Function

2. Now on the navigation bar, click on the “Object Manager” tab.

Salesforce ISOYEAR Function Example

3. Search the object name on which you want to apply the ISOYEAR function in the “Quick Find” box. As per the scenario, you need to search for the “Orders” object.

Salesforce Lightning ISOYEAR Function

4. In the left sidebar, click on the “Fields & Relationships” option. After that, click on the “New” button on the right side to create the new field.

Salesforce Lightning ISOYEAR Function Example

5. Choose the data type for specifying the type of information you want to store. As you want to use the function, click on the radio button next to the “Formula” data type. Then to proceed click on the “Next” button.

ISOYEAR Function in Salesforce

6. Enter the “Field Label” and after that click on the “Field Name” (it will be automatically populated based on the field label, but if you want to change it you can do that).

In accordance with the scenario, you can enter the field label “Quarterly Order Analysis”.

7. Scroll down to the “Formula Return Type” section, and select the data type from the list as per the requirement of the formula. According to the scenario, you need to choose the “Text” data type.

After that, click on the “Next” button to move to the next step.

ISOYEAR Function in Salesforce Example

8. Click on the “Advanced Formula” tab to create the advanced formula. Now from the “Functions” section, click on the “All Functions Categories” dropdown and select the function category that you need.

For example, as you need the “ISOYEAR” function, select the “Date and Time” category. Then, search for the required function from the category and click on it.

Once you select the function, you will get the “Insert Selected Function” button under the function section, click on it. Next, replace the parameters of the function with the merger fields, expressions, or functions as per the requirement of the scenario.

For example, as per the scenario you want to categorize the orders based on the order assignment date into different fiscal quarters with ISO year.

The formula for the scenario is given below:

CASE(
    FLOOR((MONTH(Order_Assignment_Date__c) - 1) / 3) + 1,
    1, "Q1",
    2, "Q2",
    3, "Q3",
    4, "Q4",
    "Unknown"
) & " " & TEXT(ISOYEAR(Order_Assignment_Date__c))

Here is the detailed description of the formula:

CASE(…) function: Here we have used the conditional statement i.e. CASE function that checks the value obtained in the calculated quarter and returns the string according to fiscal quarter in a below-given manner:

  • If the calculated quarter is 1, it will give the result as “Q1”.
  • If the calculated quarter is 2, it will give the result as “Q2”.
  • If the calculated quarter is 3, it will give the result as “Q3”.
  • If the calculated quarter is 4, it will give the result as “Q4”.
  • If none of the conditions is matched, it will give the result as “Unknown”.

MONTH(Order_Assignment_Date__c): Here we are extracting the month from the order assignment date field.

MONTH(Order_Assignment_Date__c) – 1: Here we are subtracting the 1 from the month value so that it starts with count 1.

FLOOR((MONTH(Order_Assignment_Date__c) – 1) / 3) + 1: Here we divide the month by 3, then round down the result to the nearest whole number using the FLOOR() function. Here we group the quarters as follows:

  • Q1: Jan-Mar
  • Q2: Apr-Jun
  • Q3: Jul-Sep
  • Q4: Oct-Dec

Then we add 1 to start the quarter from 1.

& ” ” & TEXT(ISOYEAR(Order_Assignment_Date__c): Here we use the & operator to concatenate the fiscal quarter string result obtained from the CASE with the space and the ISO year of the order assignment date.

To extract the ISO year from the order assignment date we use the ISOYEAR() function and to convert the ISO year into text we use the TEXT() function.

11. To check whether the formula is correct or has some errors, click on the “Check Syntax” button. You will get the notification “No Syntax error in merge fields or function” if there is no error. Otherwise, you will get an error message.

Optionally, you can enter the “Description“, and “Help Text” to provide additional information. After that, click on the “Next” button to proceed.

ISOYEAR Function in Salesforce Lightning

12. To grant field-level security, select the profiles to whom you want to grant edit access to the field. By default, some of the profiles are selected.

To grant access to additional profiles, click on the checkbox next to the respective profile names in the “Visible” column. Moreover, you can grant read-only access by checking the checkbox corresponding to the profile in the “Read Only” column.

Click on the “Next” button to move to the next step.

ISOYEAR Function in Salesforce Lightning Example

13. In this step add the field to the page layout By default, all the page layouts are selected. But if you don’t want to add the custom field on any one of them, unselect that page layout.

The field will be added as the last field in the first two-column section of the page layout. After that, click on the “Save” button to complete the process of using the ISOYEAR() function in Salesforce Lightning.

How to use ISOYEAR function in Salesforce Lightning

14.  Once the formula field is created, you will be able to use this formula field. Let’s see how it works:

  • Open the “Order” item, create a new order with the field “Order Assignment Date” and save the order.
  • After saving it, move to the “Detail Section” where you will see the “Quarterly Order Analysis” field with the output of the ISOYEAR function.

Let’s understand it with the example:

Suppose you have created an order with the order assignment date “31-12-2025”. After the execution of the formula, you will get the output for the quarterly order analysis “Q4-2026”.

With the output, we have concluded that the formula effectively gets the ISOYEAR of “2025” as the majority of the week is in the next ISO year “2026” and the date is “31 Dec” so it fetches quarter as “Q4”.

How to use ISOYEAR function in Salesforce Lightning Example

Now, you have learned how to use the ISOYEAR function to get the ISO 8601 week-numbering 4-digit year for the given date in Salesforce Lightning. Next, we will move on and learn how to use the ISOYEAR function in Salesforce Classic.

How to use the ISOYEAR function in Salesforce Classic

Consider a scenario where you want to calculate the difference in ISO years between the Close Date of an opportunity and the Created Date of the opportunity.

Let’s explore the steps of how to create a formula field and use the ISOYEAR function in Salesforce Classic:

1. Login into the Salesforce Classic account as an administrator. Then, click on the “Setup” option located at the top right side of the page.

Note: If you are not getting the “Setup” option located here, click on the dropdown next to your name and here you will get the option.

Salesforce Classic ISOYEAR Function

2. After that, search for the object name in the “Quick Find” box on the left side where you want to use the ISOYEAR function. As per the above-defined scenario, you need to search for “Opportunities”.

3. Now from the expanded list, click on the “Fields” option.

Salesforce Classic ISOYEAR Function Example

4. Click on the “New” button in the “Opportunity Custom Fields & Relationships” section to create the new field in Salesforce Classic.

ISOYEAR Function in Salesforce Classic

5. In this step, specify the type of information that the custom field will contain by choosing the field data type by clicking on the radio button given next to it.

According to the scenario, you need to select the “Formula” data type as we want to create the advanced formula with the use of the ISOYEAR function.

Then, to proceed, click on the “Next” button.

ISOYEAR Function in Salesforce Classic Example

6. Enter the “Filed Label” for the formula field and after that click on the “Field Name” it gets automatically populated and filled up, but if you want to change you can do that.

As per the defined scenario, you can name the field label as “ISO Year Difference”.

7. Now in the “Formula Return Type” section choose the appropriate data type for the return type by clicking on the radio button next to the desired data type.

According to the scenario result will be returned in the numerical, so select the “Number” as the data type. Optionally, you can also set the “Decimal Places” to 0 as by default it is set to 2.

Click on the “Next” button and move to the next step.

How to use ISOYEAR function in Salesforce Classic

8. Now to create the formula in the advanced formula sub-tab, click on that, and after that choose the required function category from the “All Functions Categories” dropdown.

Then, from the select function category search for the function that you require, click on that, and then click on the “Insert Selected Function” button given below the function section.

Once the function is successfully entered into the advanced formula box replace the parameters with the appropriate fields, operators, and functions to create the complete formula.

As per the scenario, you need to click on the “Date and Time” category, select the “ISOYEAR” function, and then replace the parameters according to the formula that calculates the difference in ISO years between the opportunity close date and the created date.

Below is the formula for that:

ISOYEAR( CloseDate ) - ISOYEAR( CreatedDate )

Here is the detailed description of the formula:

ISOYEAR( CloseDate): Here we use the ISOYEAR function to extract the ISO year in accordance with the ISO week date system from the CloseDate field.

ISOYEAR( CreatedDate ): Here we again use the ISOYEAR function to get the ISO year function from the CreatedDate field.

After that, we subtract the ISO year of the creation date from the ISO year of the closed date. It will procedure the difference in ISO years between the two dates in numbers.

9. Click on the “Check Syntax” button to check whether the formula is error-free or not. If it has an error, the error message will be displayed. Otherwise, it displays “No Synatx error in merge fields or function”.

Optionally, you can enter the “Description” and “Help Text” to give the extra information about the formula field. Even you can handle the blank fields if you want.

To proceed, click on the “Next” button.

How to use ISOYEAR function in Salesforce Classic Example

10. In this step, select the profiles to which you want to grant edit access to this field using field-level security. If you don’t have selected the profile the field will be hidden from the particular profile for field-level security.

Even, if you want you can setup the “Read Only” setting by checking and unchecking the checkbox next to the profile.

For example: Here I want to quickly choose all profiles in one go to give edit access allowance, so click on the “Visible” checkbox given at the top.

Then, click on the “Next” button and proceed.

ISOYEAR Salesforce Function

11. Now, choose the page layout on which you want to include this field. It will not appear on any page if you have not chosen a page layout.

By default, all the page layouts are selected, but if you don’t want to include the field in that particular page layout you can unselect the checkbox and do that.

After that, click on the “Save” button to complete the process of creating a formula field with the ISOYEAR function used in Salesforce.

ISOYEAR Salesforce Function Example

12. You can now use this formula field, let’s see the steps:

  • Open the “Opportunities” tab, create a new opportunity with the “Close Date” field, and save it.
  • After that, move to the details section page of the opportunity object and locate the “ISO Year Difference” field that will produce the result based on the ISOYEAR function.

Let’s understand it with the example:

Suppose you have created an opportunity with the opportunity closed date “12/31/2024” and it is created on “11/119/2022”. After the execution of the formula, you will get the output for the iso year difference “3”.

If you mathematically subtract “11/19/2022” from “12/31/2024”, you will get the result as “2 years”, but as you are dealing with ISO year you will get the result as “3 years” because in “2024” the majority of the week is in the next year “2025”.

Hence when you subtract “11/19/2022” from “12/31/2025”, you will get a “3 year” gap.

Example of Salesforce ISOYEAR function

With this, you have learned how to use the ISOYEAR function in Salesforce Classic.

Conclusion

In this article, we have learned about the ISOYEAR function in Salesforce that is used to return the ISO 8601 4-digit year where it considers the first day to be a Monday.

Additionally, we have discussed its use case it is used to overcome the problem of different start weekdays according to different countries. Also, we have learned the syntax with the step-by-step procedure of how to use the ISOYEAR function in Salesforce Lightning and Salesforce Classic.

You may like to read the following articles: