You need to sign in to do that
Don't have an account?

How can I select a list of tasks where the OwnerId != CreatedById?
I am trying to do the following and getting an error: "Unexpected Token"
List<
What is the correct way to select tasks where the Creator != Owner?
thanks
Task> ltsk = [SELECT id, subject, CreatedById, OwnerId FROM Task WHERE OwnerId != CreatedById];
Unfortunately, SOQL does not currently support comparing two field values in the WHERE clause. Though you can't do the above directly in SOQL, I do have a neat trick for you courtesy of our resident Force.com guru (Simon).
Create a Formula field on Task that compares the 2 fields. Something like
IF (OwnerId == CreatedById, "true", "false")
In your SOQL Query, just search on the Formula field instead:
i.e.
List<Task> ltsk = [SELECT id, subject, CreatedById, OwnerId FROM Task WHERE my_custom_formula__c = 'false'];
All Answers
Unfortunately, SOQL does not currently support comparing two field values in the WHERE clause. Though you can't do the above directly in SOQL, I do have a neat trick for you courtesy of our resident Force.com guru (Simon).
Create a Formula field on Task that compares the 2 fields. Something like
IF (OwnerId == CreatedById, "true", "false")
In your SOQL Query, just search on the Formula field instead:
i.e.
List<Task> ltsk = [SELECT id, subject, CreatedById, OwnerId FROM Task WHERE my_custom_formula__c = 'false'];
Thanks. it's really a superb solution.