+ Start a Discussion
NickDevNickDev 

Query custom fields from object with a polymorphic field

Hi,

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 seperate querie's to get to those custom fields in whaterver 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 seperate 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)];

Any help would be great! Thanks


 
SandhyaSandhya (Salesforce Developers) 
Hi,

Please refer below links which explain similar things using wrapper class.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL_polymorphic_relationships.htm


http://salesforce.stackexchange.com/questions/7355/join-2-unrelated-objects-for-pageblocktable 
 
Hope this helps you!

Please mark it as Best Answer if my reply was helpful. It will make it available for other as the proper solution.
 
Thanks and Regards
Sandhya