function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TylerM.ax1133TylerM.ax1133 

SOQL Statment - Parent - Child - Parent - Child

I am hoping that someone might be able to help me figure out a SOQL query.

 

I have four objects:

 

1. Opportunity

2. OppoPSQLineItem

3. Part_and_Service_Quote

4. Part_and_Service_Quote_Line_Item

 

OppoPSQLineItem is a junction object that connects Opportunity and Part_and_Service_Quote. Part_and_Service_Quote_Line_Item is a child of Part_and_Service_Quote.

 

What I am trying to do is display all Part_and_Service_Quote_Line_Item records for each Opportunity.

 

I know I can do the following to traverse the junction object for Opportunity and Part_and_Service_Quote information:

 

SELECT opsq.Id, opsq.Name, Opportunity__r.Id, Opportunity__r.Name, Part_and_Service_Quote__r.Id, Part_and_Service_Quote__r.Name
FROM OppPSQLineItem__c opsq

 

I can not figure out how to alter this statment so that I show Part_and_Service_Quote_Line_Item information (IE Vendor__c, Make__c, Price__c).

 

I would appreciate any help or suggestions you might have.

 

Alok_NagarroAlok_Nagarro

Hi,

 

Let's try the below piece of code -

 

Set<Part_and_Service_Quote__c> partSerIds=new Set<Part_and_Service_Quote__r>();

for(OppPSQLineItem__c oppLI: [SELECT Id,Opportunity__r.Id, Part_and_Service_Quote__r.Id from  OppPSQLineItem__c)

{

 if(oppLI.Opportunity__r.Id != null && oppLI.Part_and_Service_Quote__r.Id != null)

   partSerIds.add(oppLI.Part_and_Service_Quote__r.Id);

}

 

List<Part_and_Service_Quote_Line_Item> allRecords=[select id,IE Vendor__c, Make__c from Part_and_Service_Quote_Line_Item where Part_and_Service_Quote__c IN:partSerIds];

 

* Red marked field name might be diffrent replace accordingly

TylerM.ax1133TylerM.ax1133

Hi Alok,

 

I really appreciate the response you have provided, it would do exactly what I need if I was using apex.

 

I need to actually create one SOQL statement. This is to use with Conga Query so that I can import line items into a template with Conga Composer.

 

Do you know a way to create one SOQL query that will bring back all Part_and_Service_Quote_Line_Items given the schema I am using?