SOQL query to collect grandchild records with Polymorphic parent relationship

  • 28 June 2022
  • 3 replies
  • 213 views

Hello,
We're trying to run a SOQL query to collect grandchild records for Excel row replication, this time having a Polymorphic relationship between the grandchild object "Products Required" and its parent level as follows [Parent] Work Order > Work Order > Product Required.

 

In a similar relationship - without the polymorphism - for Account > Opportunity > Opportunity Products we used the following solution provided by @natsu_docs worked:
SELECT [fields] FROM OpportunityLineItem WHERE Opportunity.Account.Id='<<Account_Id>>'

 

For the relationship [Parent] Work Order > Work Order > Product Required we are trying with:
SELECT [fields] FROM ProductRequired WHERE (What.Type IN ('WorkOrder') AND ParentRecord.ParentWorkOrder.Id ='<<WorkOrder_Id>>')

 

APIs are as follows:

Product Required object = ProductRequired

Work Order object = WorkOrder

Product Required parent record lookup = ParentRecordId [Master-Detail(Work Order,Work Order Line Item,Work Type)]
Parent Work Order = ParentWorkOrderId

[Starting Object: WorkOrder]
 

Any help is much appreciated!


3 replies

For reference, please note that the following notation works using a static starting record (replacing Xs with actual id):
SELECT Product2Id FROM ProductRequired WHERE ParentRecordId in (select ID from workorder where ParentWorkOrderId='XXXXXXXXXXXxxxXXXX')

Nintex Support provided the solution. Thank you @KevinZ1 :



SELECT [Fields] FROM ProductRequired WHERE ParentRecordId in (select ID from WorkOrder WHERE ParentWorkOrder.Id ='<<WorkOrder_ParentWorkOrder_Id>>')

Finally, not working as expected. Results are being returned from records that are not related.

Reply