You need to sign in to do that
Don't have an account?

Combining 2 SOQL subqueries
Hi,
I have 3 objects
1. Case
2. Risk Profile
3. Investment option.
Case and Investment option has a look up field to Risk Profile.
I am trying to write a query to include details from the case, related risk profile and all the child investment options to the given risk profile.
So far I am able get the information in 2 separate queries, haven't found much luck in combining them togather.
Query 1. Select name, (SELECT name FROM investment_options__r) From Risk_Profile__c
Query 2. Select name, (SELECT name FROM Cases) From Risk_Profile__c
Any Help is appreciated.
Thanks
Talal
If it's not working ,please check the Child Relationship Name of the custom field and append __r in that.
All Answers
you are on the right track.
hope this will help.
I am geeting closer to a solution. Now I am able to combine all the queries. but doesn't seems to like case as child object to a custom object.
The first 2 samples work.
The third one is not working. I am prompted with an error message.
If it's not working ,please check the Child Relationship Name of the custom field and append __r in that.
the next error means that the "Risk_Profile__c" and "Cases" are not related to each other. Add Risk_Profile as Master or Look-up field in Cases-object.
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/relationships_among_objects.htm
Case object definitely has a lookup relationship field to Risk Profile.
1. Case has a lookup field to risk profile
2. investment option also has a lookup field to risk profile
Talal
change your code to: since it is already a query to a custom object, "__r" should now be appended.