9

Here is the SOQL query I am trying to make:

List<Task> tasks = [
   SELECT Id,ActivityDate,Status,Subject
   FROM Task
   WHERE What.Type = 'nexus__Goal__c'
   AND (What.nexus__Quarterly_Sales_Plan__c = 'a0EU0000004wz6B')
   LIMIT 101
];

Where nexus__Quarterly_Sales_Plan__c is a valid custom field I created on the nexus__Goal__c object, which is a valid target of the Task object's Polymorphic 'What' field.

When I run this query, I get the following error:

No such column 'nexus__Quarterly_Sales_Plan__c' on entity 'Name'. If
you are attempting to use a custom field, be sure to append the '__c'
after the custom field name. Please reference your WSDL or the
describe call for the appropriate names.

Will I have to wait for SOQL Polymorphism in Winter 13 in order for this Query to work? Or is there any way to make this work by specifying What.Type as I tried to do?

1
  • 1
    I have removed my answer as it was based on SFSE messing with your formatting and wasn't correct :)
    – Jon Hazan
    Sep 25, 2012 at 14:01

1 Answer 1

10

After my first answer your caught my interest so I went and had a play. I've tested using The eclipse data schema and it works for our instance:

SELECT WhatId, ActivityDate 
FROM Task 
WHERE WhatId IN (
    SELECT Id FROM Case WHERE Type = 'test'
) 

I imagine this converting to:

SELECT Id,ActivityDate,Status,Subject 
FROM Task 
WHERE WhatId IN (
    SELECT Id FROM nexus__Goal__c WHERE nexus__Quarterly_Sales_Plan__c = 'a0EU0000004wz6B'
) 
6
  • Jon, great suggestion! I will try this out and let you know how it goes for me.
    – zachelrath
    Sep 25, 2012 at 14:26
  • Looking at my answer I realise that the What.Type = 'nexus__Goal__c' line is kind of redundant!
    – Jon Hazan
    Sep 25, 2012 at 14:27
  • Yeah, that's okay :)
    – zachelrath
    Sep 25, 2012 at 14:44
  • Glad to help :)
    – Jon Hazan
    Sep 25, 2012 at 14:48
  • 1
    Jon, I removed the What.Type clause from your answer as you are correct, it is redundant. Don't want anyone to be confused and think that it makes a difference if it's there.
    – zachelrath
    Sep 26, 2012 at 13:06

You must log in to answer this question.

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