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
Morton HsiaoMorton Hsiao 

How do I put polypmorphic task fields in the predicate

Here's an easy example

select id, typeof what when opportunity then name end from task where opportunity.name = 'sql is better'
this doesnt' work.  I can't use what like
where what.name = 'sql is better' because what is a special field so that I coudl do where what.type = 'Opportunity', but then I can't do what.?
chrischris
As per the documentation : you can use typeof only in the SELECT clause of a query.
In the WHERE clause you can only filter by the TYPE as you already found out.
So you cannot filter by what.name or any other field than the SObject type.
documentation link : https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_typeof.htm