- Home
- Technical Library
- Boards
- Cookbook
- Code Share
- Blogs
- Partners
-
More
-
Services
- Training & Certification
- Support
-
Galleries
- Force.com Sites Gallery
- Chatter Challenge Entries
-
Other Web Sites
- Salesforce.com
- Database.com
- AppExchange
- CRM Community
-
Discussions
- Announcements
- General Development
- Schema Development
- New to Cloud Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules Discussion
- Security
- Mobile
- Force.com Sites
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby Development
- Adobe Flash Builder for Force.com
- Desktop Integration
- REST API Integration
- Streaming API
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- Excel Connector
- AJAX Toolkit & S-controls
- Force.com Builder & Native Apps
- AppExchange Directory & Packaging
- Force.com Labs Projects
- Open Source
- Site.com
- Jobs Board - Administrators
- Jobs Board - Developers
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- SOQL Statment - Child - Parent - Child
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
SOQL Statment - Child - Parent - Child
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-24-2012 03:40 PM - last edited on 02-24-2012 03:54 PM
Can anyone help change this SOQL statment so that I get the results that I am expecting?
I have three objects:
1. OppPSQLineItem__c (Relationship Name = Part_and_Service_Quotes__r) (Child)
2. Part_and_Service_Quote__c (Parent)
3. Part_and_Service_Quote_Line_Item__c (Child)
I am trying to filter based on an ID (Cost_Sheet__c) from the object OppPSQLineItem__c and show all the related records in the objects sibling (Part_and_Service_Quote_Line_Item__c). The statement will bring back ALL records contained in Part_and_Service_Quote_Line_Item__c as it is a right outer join. Any way to change to a left join? Am I coming at this from the wrong direction?
SELECT Id, (SELECT Id, Cost_Sheet__c FROM Part_and_Service_Quotes__r WHERE Cost_Sheet__c = 'a0R60000000aIhY'), (SELECT Id FROM Part_and_Service_Quote_Line_Items__r) FROM Part_and_Service_Quote__c
I really appreciate any help and effort anyone in the community puts forth!
Regards,
Tyler
Re: SOQL Statment - Child - Parent - Child
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-24-2012 04:07 PM
I may not beunderstanding correctly but you may have to get a set of IDs you want to return. I am assuming Cost_Sheet__c is common between the two children?
Set<ID> csIDs = New Set<ID>();
For(OppPSQLineItem__c o : [SELECT Id, Cost_Sheet__c FROM Part_and_Service_Quotes__r WHERE Cost_Sheet__c = 'a0R60000000aIhY']){
csIDs.add(o.id);
then
SELECT Id, (SELECT Id FROM Part_and_Service_Quote_Line_Items__r Where Cost_Sheet__c IN :csIDs) FROM Part_and_Service_Quote__c
Re: SOQL Statment - Child - Parent - Child
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-24-2012 04:11 PM
Hi Starz26,
I really appreciate the response! Unfortunately, Cost_Sheet__c is actually not common between the two children (this would make your solution perfect). Cost_Sheet__c is actually a Parent of OppPSQLineItem__c. OppPSQLineItem__c has actually been created to model a many-to-many relationship between Cost_Sheet__c and Part_and_Service_Quote_Line_Item__c.
Does this give enough information to help with a different solution? Unfortunately I am still banging my head against a wall!
Tyler
Re: SOQL Statment - Child - Parent - Child
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-24-2012 04:33 PM
Seems like I was too hasty heading to the community to find the answer. It appears the following statement works:
SELECT Name, (SELECT Id, Name, Labour_Hours__c, Make__c, Model__c, Price__c, Quantity__c, Line_Description__c, Subtotal__c FROM Part_and_Service_Quote_Line_Items__r) FROM Part_and_Service_Quote__c WHERE Id IN (SELECT Part_and_Service_Quote__c FROM OppPSQLineItem__c WHERE Cost_Sheet__c = 'a0R60000000aIhY')
Thanks for the help!
Re: SOQL Statment - Child - Parent - Child
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-24-2012 04:41 PM
I was just going to send something similiar....glad you got it working.

