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
JHONG FREE 2JHONG FREE 2 

Query result(s) based on other query results

Hi Experts,

I am a really newbee with this Apex and SOQLs. 

How would I do this?

I would like to compare so I can get filtered results:

Logic would look like this:

query1: SELECT Id, Parent_ObjectA__c FROM Child_ObjectA__c 
query2: SELECT Id, Parent_ObjectA__c FROM Child_ObjectB__c

I would like to grab the IDs of Child Records, from two different Child Objects, that looks up on the same Parent  Record.

How would I do this?

I appreciate any help you can give me.

Thanks !

FYI: I am really dumb with APEX so if you can have additional remarks, I would really appreciate it.
SrikanthKuruvaSrikanthKuruva
I did not quite get the logic you are trying to achieve but i understand you are trying to do something like

select id,(select id from contacts),(select id from opportunities) from Account

For more info on relationship queries on objects you can check the following link.
http://www.salesforce.com/us/developer/docs/dbcom_soql_sosl/Content/sforce_api_calls_soql_relationships.htm

sandeep@Salesforcesandeep@Salesforce
Hi Friend, 

It is very simple to do like this 
Lets say I hve two child object A , B under Parent Object P then if you look in to A nd B object's Object Schema nd feld by which they are connected with P. You will find cjild relationship name. Let say child relationship names are ra, rb then SOQL would be 

P__c P = [Select id , (Select id  from ra__r ) , (Select id from rb__r) from P__c  where id : Pid] ;

Here you will get 

List<a__c> aList = P.ra__ r;
List<b__c> bList = P.rb__ r;

please let m know in case of any issue.
pradeep naredlapradeep naredla
HI JHONG FREE,
        you can write an inner query for that check the link below


http://blog.jeffdouglas.com/2010/02/22/soql-how-i-query-with-thee-let-me-count-the-ways/