I am trying to query the ProcessInstanceWorkitem
object which has a relationship to the ProcessInstance
object, however the ProcessInstance
object has a polymorphic relationship by using the TargetObject
field.
The question is, with my query below - I understand I can either use separate queries to get to those custom fields in whatever object relates to them or you could use TYPEOF (although that does not seem to be enabled or possible yet).
So I am left with option 1 of having a separate query, the issue is I don't quite understand how I can do a second query of this related object and get to the custom fields and them combine them into one List so I can display in a PageBlockTable?
Here is my query:
results = [Select p.ProcessInstance.Status,
p.ProcessInstance.TargetObject.Name, p.Actor.Name, p.CreatedBy.Name,
p.CreatedDate FROM ProcessInstanceWorkitem p WHERE
(CALENDAR_MONTH(p.CreatedDate) = : dropdownMonth AND
CALENDAR_YEAR(p.CreatedDate) = :dropdownYear)];
When performing a second query, the issue is these results need combining so I can just display the additional fields from the other object I am selecting the fields from.