function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

soql semi join trouble

I am trying to select records owned by a certain user but am getting an error:


 Cannot use a polymorphic key for outer field for semi join


here is my query:


SELECT Name, Id, OwnerId
FROM lead
WHERE OwnerId in (SELECT id FROM user WHERE Username like '')


SOQL syntax is different from SQL. In your case you need to use the following statement:


Select Id, Name, OwnerId  from Lead where Owner.UserName like ''



Check out this link:

Ok, my other question is: is it possible to select not just the leads that are owned by user xxx but also the leads that are visible to them?