+ Start a Discussion
RadnipRadnip 

Can you do a Sub query on a lookup relationship?

Can you do a sub query on a lookup relationship?

 

I'm doing the following but keeps saying "Didn't understand relationship 'Sub_Product__c'..." I've tried Sub_Product__r as well but same error.

 

SELECT Id, Type__c, (SELECT Id, Product__r.Name, Subscription_loc__c FROM Sub_Product__c)
FROM Subscription_loc__c WHERE Subscription__c = :opp.Subscription__c 

 

Alex.AcostaAlex.Acosta

When doing these types of query, you'll need to use the child relationship name on your inner query. Go to your sObject Sub_Product__c click on the lookup field to Subscription_loc__c  and within this field details page, you'll see something called `Child Relationship Name`. Use this name as your subquery from clause. You may need to append __r if it's a custom sObject.

 

If this answers your question pleaes mark this so others can benefit from it.