Code snippet1:
list<string> abc = new list<string>{'a1V44000008TyEEEA0'};
list<task> t = [ SELECT Id FROM Task WHERE (whatId in :abc or Whoid in :abc)]
system.debug('-->'+t.size());
Above code segment is working as expected.
Code snippet2:
list<string> abc = new list<string>{null, 'a1V44000008TyEEEA0'};
list<task> t = [ SELECT Id FROM Task WHERE (whatId in :abc or Whoid in :abc)]
system.debug('-->'+t.size());
Snippet2 is returning a result as if there is no WHERE clause. What is the logic behind this or is it any bug?
The query in your second code snippet will return all task records where
whatId
orWhoId
equalsnull
ora1V44000008TyEEEA0
. Probably in most of your task recordswhatId
orWhoId
is NULL ora1V44000008TyEEEA0
.You can execute:
list<task> t = [ SELECT Id FROM Task WHERE (whatId != NULL or Whoid != NULL)]
to check if there is any task where both
whatId
andWhoid
is notnull
.