2

I have to check whether a list<Order> is empty or null.I can use isEmpty() to check this.

But Can I use isBlank() with list<Order> to check.

1
  • I was thinking the same.Thanks for the comments guys.
    – devsfdc
    Commented Feb 11, 2016 at 12:52

3 Answers 3

4

In addition to the above

a common pattern I see in posts is this:

if (!myListOfSobjects.isEmpty())
  insert myListOfSobjects;  // do some DML -- could be update, delete, upsert too

this is all unnecessary - just do the DML; if list is empty, SFDC does nothing. Code is cleaner

  insert myListOfSobjects;  // do some DML -- could be update, delete, upsert too

another pattern sometimes seen in posts is this

if (myListOfObjects.size() > 0) {
  for (myObject m : myListOfObjects) {..}

this too is unnecessary; just do as shown below; if the list is empty, no iterations are done

for (myObject m : myListOfObjects) {..}
3

No. isBlank is a Formula operator which can be used to check if a field value is blank or not.

so, you can use only one of the below:

list != null  //Null check
list.isEmpty()  //Check if its blank
list.size() == 0  //Compare size
1
  • 1
    also String.isBlank() is useful for testing if a string is null or empty string
    – cropredy
    Commented Feb 11, 2016 at 14:49
0

There is no such method called isBlank supported by the List Class. Please refer the available methods of for List here.

To check if list is empty you can either use

list.isEmpty() 

or

list.size() == 0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .