Salesforce BLANKVALUE Function

In this Salesforce Tutorial, we will learn the Salesforce BLANKVALUE Function. We will also understand the syntax to write the function and examples to know exactly how it works.

Additionally, we will go through some use cases and consideration of the BLANKVALUE function in Salesforce and learn the step-by-step implementation of how to use the BLANKVALUE function in Salesforce Lightning and Salesforce Classic.

What is Salesforce BLANKVALUE Function

The Salesforce BLANKVALUE function is one of the logical functions of Salesforce that is used to handle the null or blank values within the Salesforce formulas.

The BLANKVALUE function in Salesforce checks whether the expression is blank and returns a substitute expression if it is blank. If the expression is not blank, it returns the original expression value.

The syntax of the function is as given below:

BLANKVALUE(expression, substitute_expression)

Here:

  • expression: The expression parameter represents the field or value that we want to check whether it is null or blank.
  • substitute_expression: The substitute_exprsession parameter is the value that will be substituted if the expression is null or blank.

With this, we have understood the meaning of the BLANKVALUE function with the syntax. Now, let’s move on and discuss the use case and considerations of the function.

Use Case and Consideration of BLANKVALUE Function

The use case of the BLANKVALUE function is to prevent the formula errors returned by the null or blank values. It basically enhances the readability of the function and also allows us to set the dynamic default values.

Let’s understand, with example, how the BLANKVALUE function actually works.

For example, we want to check whether the account name is null; if it is, we want to return “No Name Available”.

BLANKVALUE(Account.Name, 'No Name Available')

Moreover, there are many considerations of the BLANKVALUE function. Let’s discuss each of them:

  • It is recommended to use the BLANKVALUE function instead of the NULLVALUE. The BLANKVALUE has the same functionality as the NULLVALUE; the only difference is that it is also supported in the text fields.
  • If a field has zero, a blank space, or a character in it, it is not empty. A field that has a space entered using the spacebar, for instance, is not empty.
  • If the field is empty, use the BLANKVALUE method to return a given string; if you simply want to make sure the field is filled in, use the ISBLANK function.
  • The function returns the substitute expression with a numeric field if the field doesn’t have a value and is not set up to handle blank values as zeroes.

Now, we have covered the use case, examples, and considerations of the function. Let’s move on and learn to use the BLANKVALUE function in Salesforce Lightning.

How to use BLANKVALUE Function in Salesforce Lightning

The following are the below-given steps to use the BLANKVALUE function in the Salesforce Lightning formula field.

Let’s discuss it with the help of the scenario: Suppose we want to fill up the mailing address in the other address fields if the mailing address is null or blank.

Step-1: General Steps to Use Function in Formula Field:

Log in to the Salesforce account as an administrator with the help of credentials. If you are not on the “Setup Home” page, click on the “Gear” icon on the top right side and select the “Setup” option from the dropdown.

See also  BEGINS() Function in Salesforce

Select the “Object Manager” tab given on the navigation bar.

Salesforce BLANKVALUE Function

Now, search for the object on which one wants to use the BLANKVALUE function in the “Quick Find” box. As per the scenario, we can search for the “Contact” object.

Salesforce BLANKVALUE Function Example

Click on the “Fields & Relationship” option; after that, click on the “New” button given on the top right of the upcoming page.

Salesforce Lightning BLANKVALUE Function

Step-2: Choose the Field Type

Specify the type of information that the custom field will contain by choosing the appropriate data type from the list.

As per the scenario, we need to go for the “Formula” data type, so we check the radio button next to it.

After that, click on the “Next” button and proceed.

Salesforce Lightning BLANKVALUE Function Example

Step-3: Choose the Output Type

Enter the “Field Label” the name that you want to display for that field. Afterward, once you click on the “Field Name”, it gets automatically populated.

In accordance with the scenario, we can give a field label as “Default Other Address”.

Scroll down and select one data type from the list that can suit your formula return type. According to the scenario, we need to choose the “Text” data type as the return type of the formula.

To proceed, click on the “Next” button.

How to use BLANKVALUE Function in Salesforce Lightning

Step-4: Enter Formula

Click on the “Advance Formula” subtab to enter the formula with the use of additional fields, operators, and functions.

After that, move to the “Function Section” select “All Function Categories” -> click on “Logical” -> search, and select “BLANKVALUE” -> click “Insert Selected Function”.

If you require more functions, you can add them similarly, and to add the fields and operators, click on the “Insert Field” button and “Insert Operator” select, respectively.

For example, here, we create the formula that checks if the other address is null or blank; the mailing address will substituted. Here is the formula given below:

BLANKVALUE(  OtherStreet , MailingStreet ) & ', ' &
BLANKVALUE(  OtherCity , MailingCity) & ', ' &
BLANKVALUE(  OtherState , MailingState ) & ' ' &
BLANKVALUE(  OtherPostalCode , MailingPostalCode )

Here is a detailed description of the formula:

  • BLANKVALUE(OtherStreet , MailingStreet): If the OtherStreet is null or blank, substitute the MailingStreet value.
  • BLANKVALUE(OtherCity , MailingCity): If the OtherCity is not empty, use the OtherCity value; otherwise, fill it with the MailingCity value.
  • BLANKVALUE(OtherState , MailingState): If the OtherState is null or blank, substitute the MailingState value.
  • BLANKVALUE(OtherPostalCode , MailingPostalCode): If the OtherPostalCode is not empty, use the OtherPostalCode value; otherwise, fill it with the MailingPostalCode value.
  • & ‘, ‘ &: It is used to concatenate the result with a comma and a space.

To determine whether your formula is error-free or includes errors, click the “Check Syntax” button after inputting the formula.

You have the option to include the “Description” and “Help Text” as well if you want. Click the “Next” button to move on to the next step.

BLANKVALUE Function in Salesforce

Step-5: Establish Field Level Security

In this step, we will get the matrix that shows the profiles associated with Salesforce.org. Here, we can set the visibility of a profile on a particular field by checking the checkbox in the “Visible” column.

See also  Salesforce PRIORVALUE Function

We can also adjust the “Read-Only” access for each profile based on our requirements by checking the checkbox in the “Read Only” column.

Click on the “Next” button to proceed.

BLANKVALUE Function in Salesforce Example

Step-6: Add to Page Layouts

Choose the page layout on which you want to include this field. The field won’t show up on any page if you have not chosen the layout.

Note: The field will be added as the last field in the first 2-column section of the page layout.

After that, click on the “Save” button to complete the process.

BLANKVALUE Function in Salesforce Lightning

Step-7: Testing of formula having BLANKVALUE function.

To check how the formula is working. Follow the below steps:

  • Create a new contact by opening the “Contacts” item, fill in the necessary fields (such as Mailing Address Fields), and save it.
  • Move to the “Details” and locate the “Default Other Address” field. The result of the field shows you how the BLANKVALUE function works depending on the conditions.

Let’s understand it with the example:

  • Suppose we have created a contact and filled in all the fields of mailing address “123 Main Street, Anytown, CA 12345” but have not filled in the other address fields.
  • Now, when we save it, the formula will execute and find the field blank, so it automatically fills up the other mailing address, “123 Main Street, Anytown, CA 12345,” because of the BLANKVALUE function.
BLANKVALUE Function in Salesforce Lightning Example

With this, we have learned how to use the BLANKVALUE function in Salesforce Lightning. Let’s proceed and learn to use the BLANKVALUE function in the Salesforce Classic formula field.

How to use BLANKVALUE Function in Salesforce Classic

Suppose you have a scenario where you want to set the default close date for an opportunity if already not specified.

Let’s learn to use the BLANKVALUE function in Salesforce Classic to fulfill the desired scenario requirement. The steps are as given below:

1. Login into the Salesforce account as an admin in the Classic Interface. Then, click on the “Setup” option given at the top right side.

Salesforce Classic BLANKVALUE Function

2. Use the “Quick Find” box on the left side of the page and search the object in whose field you want to use the BLANKVALUE function. Then click on the “Fields” option of the particular searched object.

According to the scenario, we need to search for the “Opportunities” object.

Salesforce Classic BLANKVALUE Function Example

3. Scroll down to the “Opportunity Custom Fields & Relationship” section, and click on the “New” button.

BLANKVALUE Function in Salesforce Classic

4. In this step, choose the data type that we will require. According to our scenario, we need the “Formula” field as we want to create the formula having the BLANKVALUE function.

After that, click on “Next” and move on to the other step.

BLANKVALUE Function in Salesforce Classic Example

5. To set up the name for the field, fill it up in the “Field Label” and once you click on the “Field Name” field box, it gets automatically filled according to the field label.

Choose the data type that will store our return result as per the requirement of the formula; we need to pick the “Date” data type.

According to the scenario, we can set the field label as “Predicted Closed Date”.

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

How to use BLANKVALUE Function in Salesforce Classic

6. To create the formula, choose the “Logical” category from “All Function Catergories”. Then, search for the required functions such as “BLANKVALUE”, click on it, and then click on “Insert Selected Function”.

See also  ISCHANGED Function in Salesforce

Replace the parameters of the function with the merger fields, expressions, or functions as per the requirement of the scenario.

For example, we want to set a predicted close date as the date from today to the next 30 days for opportunities if the close date is not specified. The formula is as follows:

BLANKVALUE(CloseDate, TODAY() + 30)

Here is a detailed explanation of the formula:

  • CloseDate: It is the field that represents the date of closing an opportunity.
  • TODAY() + 30: Here, we are trying to calculate the expected closing date, till not filled by the administrator, by adding 30 days to the current date.
  • BLANKVALUE(CloseDate, TODAY() +30): Here, we are checking whether the close date is blank, null, or empty with the help of the BLANKVALUE function. If it is blank, it uses the above-calculated value; otherwise, it uses the CloseDate value.

Select the “Check Syntax” button to see whether there are errors in the formula or if it is correct. We have the option to enter the “Description” and “Help Text” also; if we want, we can add them.

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

How to use BLANKVALUE Function in Salesforce Classic Example

7. In this step, we need to choose the profiles to which we want to grant edit access using field-level security. By checking the box in the “Visible” column, we can adjust a profile’s visibility and also provide read-only access by checking the box in the “Read Only” column.

To proceed, click on the “Next” step.

How to use BLANKVALUE Function in Salesforce

8. In this step, add the field to the page layout. However, we can deselect the page layout if we don’t want to add the custom field to any of the ones that are already selected.

Click on the “Save” button to complete the process.

How to use BLANKVALUE Function in Salesforce Example

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

  • Create the “Opportunities” object, fill out the necessary fields, and save it.
  • Move to the “Details” page and find the “CloseDate” field; it will give you the result according to the BLANKVALUE function, depending upon the condition.

Let’s understand it with the example:

  • Suppose you have created an opportunity on “01/12/2024” with the close date so that the BLANKVALUE function will execute and calculate the close date as “01/12/2024”.
Example of Salesforce BLANKVALUE Function

With this, we have learned how to use the BLANKVALUE function in Salesforce Classic in the formula field.

Conclusion

With this, we have learned about the BLANKVALUE function in Salesforce. We have also learned the syntax, use cases, examples, and considerations of the function.

Additionally, we have learned step-by-step how to use the BLANKVALUE function in Salesforce Lightning and Salesforce Classic with real business-based examples.

You may like to read: