Tag Archives: Salesforce formula

Salesforce: Check Null/Empty Value of A Field

In Salesforce, it is very common that we build formula field, validation rule or workflow rules to act on the data of a field and sometimes we would like to validate on an empty value. In Salesforce formula editor, there are two functions: ISBLANK() and ISNULL(). The question here is, which is the correct one that we should use?

ISNULL()

This is an old function that works with most of the field types except Text, Text Area and Long Text. (reference)

ISBLANK()

This is a new function that Salesforce introduce to support the empty field validation on Text fields. It also works with other field types. According to Salesforce documentation, it is recommended to use this function instead. (reference)

Please note that if you are referencing a formula field with the option “Treat blank fields as zeroes”, the formula field will give value zero and won’t be considered as null.

Above is how you can validate an empty field in formula editor. How can we achieve the same in Apex?

Text Fields

There are a few options to validate empty text fields in Apex:

Use String.isBlank() method. This will return true if the text field is empty.
Compare the text field to an empty string, e.g, Account.Name == ”. You shouldn’t use NULL as text field in Salesforce is never considered NULL. Note that String variable can still be considered NULL.

Checkbox Fields

This can be compared by using TRUE or FALSE. This is because an unchecked checkbox field is considered as FALSE instead of NULL.

Other Fields

You should compare the field value to a NULL.

Wedid: Commission Calculations

Challenges

A referral agency gains profit by referring potential customers to sign up for telco services. There more than 10 contractors who are tasked to call the potential customers and sell the service to them. If a customer signs up, the referral agency will pay commission based on the type of services. At this moment, the commissions are being calculated manually in a spreadsheet and it is hard to keep track for each contractors across the whole FY.

Solution:

A solution is design to tie each service with a commission amount. When an Opportunity is closed won, the commission will be auto calculated. The user can also run a report to display a list of contractors and the total commissions that they are entitled of.

Related Objects User, Opportunity, Products
Components Formula, Validation Rules, Workflow, Report
Complexity Low