The expression:
[Select id from CustomObj1__c]
produces a list of CustomObj1
. That code will never produce a null
but it may produce an empty list. (Code should only include null
checks where nulls can occur and they can't occur here.)
You can define a variable of the right list type using either of these syntaxes; the first one is a little shorter and looks a little more symmetrical:
CustomObj1__c[] objects = [Select id from CustomObj1__c];
or:
List<CustomObj1__c> objects = [Select id from CustomObj1__c];
Once you have the objects
variable, you can invoke any of the list methods on it including isEmpty() and size():
if (!objects.isEmpty()) {
...
}
or:
if (objects.size() > 0) {
...
}
or better just:
for (CustomObj1__c o : objects) {
...
}
or even better just:
for (CustomObj1__c o : [
Select id
from CustomObj1__c
]) {
...
}