Reputation: 953
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?
Upvotes: 0
Views: 1543
Reputation: 2223
The query in your second code snippet will return all task records where whatId
or WhoId
equals null
or a1V44000008TyEEEA0
. Probably in most of your task records whatId
or WhoId
is NULL or a1V44000008TyEEEA0
.
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
and Whoid
is not null
.
Upvotes: 2