function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ethan huntethan hunt 

best way to check null in collections.....

Hi All,

Could you please let me know which are the best practice to check null in List, Map, Set to avoid nullpointer exception....

Regards
karnadesaikarnadesai
For String fields, you should use '' check and for number/Id fields, you should use NULL check.

In some cases, you might face some weird issues with such comparisons, the workaround then is to check for both :D

For Collections I use size() method.
brian.cline1.392305187066454E12brian.cline1.392305187066454E12
I have a custom function that basically calls both ISNULL & ISBLANK
Nirmal ChristopherNirmal Christopher
you can put a If check. like this if(list.size()>0){
...
}