1

I have to retrive datas from 2 custom object and sobject Product2,

Object details as follows,
object name :delv__dftly_Delivery_Checkouts__r 

Field name      API Name                   Data type
dftly tasks    delv__ForTask__c            Lookup(dftly tasks).
Product       delv__ItemRequired__c        Lookup(Product)

I have tried writing the query as below separatly join 2 object.

select ID, (select ID, delv__ItemRequired__c from delv__dftly_Delivery_Checkouts__r) from Product2 select Id, (select ID from delv__dftly_Delivery_Checkouts__r) from delv__dftly_tasks__c

How can i make this 2 queries into a single query and retrieve data in single run.

1
  • you can't make both soql into one.. one way is query from child objects to parent object... if you thinking to query from parent to child then you can't do that because you have 2 parent object is there
    – Ratan Paul
    Jul 18, 2016 at 8:18

1 Answer 1

1

Depending on what information you need, you have two ways of doing this:

Option 1

SELECT Id, delv__ItemRequired__c, delv__ForTask__c, delv__ItemRequired__c 
FROM delv__dftly_Delivery_Checkouts__c

In this case

  • the field delv__ForTask__c holds the task Id
  • and delv__ItemRequired__c holds the product Id

From your queries it appears that the Id is the only information you need. If you need other fields from one of the objects you need to use delv__ItemRequired__r.Field_You_Want__c like this:

SELECT Id, delv__ItemRequired__c, delv__ForTask__c, delv__ItemRequired__c, 
      delv__ItemRequired__r.Field_You_Want__c 
FROM delv__dftly_Delivery_Checkouts__c

Option 2

SELECT Id, delv__ItemRequired__c, delv__ForTask__c  
FROM delv__dftly_Delivery_Checkouts__c 
WHERE delv__ItemRequired__c 
          IN (SELECT Id FROM Product2) 
      AND delv__ForTask__c 
          IN (Select Id FROM delv__dftly_tasks__c)

This will return Delivery Checkouts that have a product and a task. You can add filters (WHERE ...) to narrow it down


Take a look at this page for more info on relationship queries.

1
  • Thanks, Fernando this is what i needed. Option 1 worked for me.
    – Chandu
    Jul 18, 2016 at 9:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .