+ Start a Discussion

SOQL: To Retrieve Data from two Unrelated Sobjects

Hi ! I have to get data from 2 SObjects which have no relationship.


SObject 1:




SUPPLIER_NUMBER    SUPPLIER_NAME           STATUS                      CITY


S1                                           abc                                      20                          MUMBAI        



Sobject 2:




Project_Number    Project_Name     City     


          J1                       SORTER           Chennai

          J2                       Display              Nellai



The Query Is : "Get supplier number for suppliers who supply Project J1".


Please give your suggestions.





pretty odd question ... then how you are maintaining  that for J1 project who are the suppliers

This is a part of Query practice questions. I do not have an idea, how to solve such queries.
If you have multiple suppliers for a project, you will need to have a third object to link the two together.

So you would have in layer order:

1. Project
2. Project Supplier
3. Supplier

The project supplier is simply a link between the project and supplier.

You can then run a query on the project supplier object to bring together the two objects:

SELECT Id, Project__r.Name, Supplier__r.Name FROM ProjectSupplier__c WHERE Project__c=:PROJECT_ID
I will check the schema one more time.