I created an email template, component and controller that will send different set of records for each user that has a specific profile. I am having problems in my query in selecting the users that is based on opportunity owner based on task that has a status = 'Open'.

I have the following query:

User[] users = [SELECT Id, Name, Email FROM User 
                WHERE Id IN 
                   (SELECT OwnerId FROM Opportunity WHERE Id IN 
                       (SELECT WhatId FROM Tasks WHERE Status = 'Open'))
                AND ProfileId IN 
                  (SELECT Id FROM Profile WHERE Name IN ('Project Lead', 'Project Lead - Expert'))]; 

What I need is to get the set of users/owner of opportunity where the opportunity's task status is set to Open.

Any help is very much appreciated. Thanks!


1 Answer 1


For sure, you can only have one level of parent to child in soql, so you'll have to split them up.

To get around this, query the tasks that match your description, then use that list to get the Opptys and owners.

  • 1
    a further issue is that Task can't be used in an inner semi-join
    – cropredy
    Nov 20, 2014 at 4:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .