+ Start a Discussion

SOQL where clause using $user.id

I'm trying to do a select for data for the currently logged in user with the global variable {!$User.id} in a trigger.
This statement runs fine:
[SELECT j.id, j.Subject, j.CallDurationInSeconds, j.CreatedDate, j.status, j.Description, j.CreatedByID  
FROM Task  j  WHERE (j.CreatedDate = today AND CreatedByID = '00540000001Gii5AAC' AND j.Status = 'Completed')
But when I replace the hard coded ID with {!User.id} I get an error.
Thanks, Michele
Best Answer chosen by Admin (Salesforce Developers) 
SELECT j.id, j.Subject, j.CallDurationInSeconds, j.CreatedDate, j.status, j.Description, j.CreatedByID  
FROM Task  j  WHERE (j.CreatedDate = today AND CreatedByID =:UserInfo.getUserId() AND j.Status = 'Completed')