I am using the polymorphism in my SOQL queries which is working fine, an generic example of the query is below
SELECT
TYPEOF What
WHEN Account THEN Phone, NumberOfEmployees
WHEN Opportunity THEN Amount, CloseDate
ELSE Name, Email
END
FROM Event
Now if i want to only query all the Event associated to all accounts which have a phone number of '123456', is that possible? I would need to use polymorphic fields in my where condition. I am trying the syntax but i am getting issues, not very sure if we can use polymorphism in where condition. What i am trying to get is something like this but is not working
SELECT TYPEOF What WHEN Account THEN Phone, NumberOfEmployees WHEN Opportunity THEN Amount, CloseDate ELSE Name, Email END FROM Event where TYPEOF What WHEN Account THEN Phone Else Name END ='123456'
where whatid in (select id from account where phone = '123456') or whatid in (select id from opportunity where name = '123456')