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
letternumberletternumber 

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 'xxx@xxx.com')

ShamilShamil

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 'xxx@xxx.com'

 

 

Check out this link: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_relationships.htm

letternumberletternumber
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?