Skip to main content

Polymorphic Query

Professional

Polymorphic Field is a field that can look up to more than one Object. For ex., Task.WhatId, Event.WhatId or Attachment.ParentId etc.,

If you want to fetch related parent record information, you can’t use typical SOQL relationship names as those names may not be valid in all Objects that Poly Field can point to. Instead, you must use Poly Field clause in SOQL.

For ex.,

SELECT
TYPEOF What
WHEN Account THEN Phone, NumberOfEmployees
WHEN Opportunity THEN Amount, CloseDate
END
FROM Event

Brobench supports executing those queries fine. However, it is painful to construct such queries. Execute as Polymorphic Query automates construction of Type Of clause behind the scene.

For ex., if you run select Id, What.Phone, What.NumberOfEmployess, What.Amount, What.CloseDate from Event, via the above option, app transform that query to above Type Of clause and executes it.