Find your content:

Search form

You are here

SOQL query on fields related by polymorphic lookups


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?

Attribution to: zachelrath

Possible Suggestion/Solution #1

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 
    SELECT Id FROM Case WHERE Type = 'test'

I imagine this converting to:

SELECT Id,ActivityDate,Status,Subject 
FROM Task 
    SELECT Id FROM nexus__Goal__c WHERE nexus__Quarterly_Sales_Plan__c = 'a0EU0000004wz6B'

Attribution to: Jon Hazan
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content