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
WebNXWebNX 

SOQL Relationship Query

Hello Everyone,

 

I am have problems querying User's Task by using the following formula below. I just want to view task that the user(s) may have for today, but I am getting a error message stating Invalid Type.

 

Select Id, Name, Email,

(Select Subject, ReminderDateTime From Task Where ReminderDateTime = TODAY)

From User

 

Can someone please help me with this problem? Thanks in advance.

SidharthSidharth

Try this:

 

List<Task> tsk = [Select Subject, ReminderDateTime From Task Where ReminderDateTime = TODAY and OwnerId =: User.Id ];

 

where User.id is the Id of the user you want to retrive the tasks for.

WebNXWebNX

Sorry Sidharth,

 

But that is not what I am looking for. I am looking to join the two queries into one using relationship querying with an inner and outer join. By using the user level join and then look at all the task for that user has in the inner join. What you post is correct but not for what I want. I don't want make two separate queries in my code just one; this way I won't go over the governor limits in salesforce. If you try this query search below it will give you all the accounts along with the contacts with the account.

 

SELECT Name,
  (
    SELECT LastName
    FROM Contacts
  )
FROM Account

Now, trying the same formula to try to get the user's task(s) it won't work, and I have no idea why? But thanks for your help!

 

 

Ritesh AswaneyRitesh Aswaney

How about ?

 

Select OwnerId,Owner.Name, Owner.Email,Subject, ReminderDateTime  From Task Where ReminderDateTime = TODAY order by OwnerId

 

I dont believe you can do that sort of inner query with Tasks - they're a 'special' object.