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
Sophia Abraham 6Sophia Abraham 6 

Can we query with an INNER JOIN between 2 non-related Custom Objects


Hi All,
I am trying to make REST API calls to query custom objects and return records.
I have been successful in doing this for one custom object.
Now, I have 2 completely non-related Custom objects and would like to make an INNER JOIN using 2 fields from the 2 objects
For Example,
Object 1
fields: Name, ID, Description
 
Object 2 
fields: User_Name, ID, Age
Now get all records where obj1.Name=obj2.User_Name and obj1.ID=obj2.ID


can this be done? Without any realation between obj 1 and obj 2
And if yes, How? A small example query would be greatly helpful
Thanks in Advance.
Ayush TripathiAyush Tripathi
Refer the below code for querying 2 non-related objects in Salesforce. 
 
Set<String> records = new Set<String>();
for(Object1  rec: [SELECT Name FROM Object1]){
    records.add(rec.Name);
}
List<Object2> list = [SELECT Name FROM Object2 WHERE Name  IN :records];

 
Sophia Abraham 6Sophia Abraham 6
Hi Ayush,

Thanks for your reply. 
Will try this out in Java and get back to you!
Sophia Abraham 6Sophia Abraham 6
Hi Ayush,

I tried to implement the same in Java code with REST APIs and I don't think IN is supported. Do you have any sample REST API java snippets I can maybe try out?

Thanks,
Sophia