0

These are the methods I use to check if a field is empty:

p.Call_Summary__c != null 
p.Call_Summary__c!=''

And these are the methods to check that a list isn't empty:

CClist != null 
CClist.isEmpty()!=null

Do you recommend on anything else? What's the difference between 'isEmpty' to '!=null'?

Thank you

1

For lists the difference is that

CClist != null

Checks if you declared the list. You can't use isEmpty() on a non-declared list - it'll throw you an Exception.

CClist.isEmpty()!=null

Will always return true(if list is declared), because it shows whether or not list has elements and will never return null. It always returns either true or false. In order to check if list has elements you need to check both:

if (CClist != null && !CClist.isEmpty())

Or

if (CClist != null && !CCList.size() >0)
  • Is there a difference between '!CClist.isEmpty()' to 'CCList.size() >0' ? – Json Nov 30 '16 at 8:25
  • @Barracks no difference at all. – EvAzi Nov 30 '16 at 9:01
0

isEmpty returns true or false so in your example if it was empty or not it would evaluate to true.

CClist.isEmpty()!=null

string fields you can use string.isBlank or string.isNotBlank

For lists and sets you can use

set.isEmpty() which returns true if it is or false if it is not

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.