You need to sign in to do that
Don't have an account?
Violet
SOQL query to get list of custom objects that have lookup relationship with opportunity
A (custom object) has a custom lookup relatiomship to Opportunity(Opportunity_Name__c). Trying to write SOQL query to get the list of custom objects but none of the below statements are working:
select Id,(select Id from A__c) from Opportunities
select Id, (select Id from Opportunity_Name__c) from A__c
select Id,(select Id from A__c) from Opportunities
select Id, (select Id from Opportunity_Name__c) from A__c
Alternatively, if you want to query the opportunities and all of the child Custom Objects you could do it this way.
In the second query above notice I added the __r instead of __c. This identifies a relationship. To find the actual name of this relationship go to Setup > Create > Objects > Custom Object Name. Then click on the Opportunity_Name__c field to get the details of that field. You should see a text box called Relationship. Replace "Custom_Objects__r" with the actual relationship name.
To access the child objects from the second query you need to go through the Opportunity, like this:
Hope that helps,
Clint
All Answers
Alternatively, if you want to query the opportunities and all of the child Custom Objects you could do it this way.
In the second query above notice I added the __r instead of __c. This identifies a relationship. To find the actual name of this relationship go to Setup > Create > Objects > Custom Object Name. Then click on the Opportunity_Name__c field to get the details of that field. You should see a text box called Relationship. Replace "Custom_Objects__r" with the actual relationship name.
To access the child objects from the second query you need to go through the Opportunity, like this:
Hope that helps,
Clint
Please try the below query. 'As__r' is the Opportunity to the custom object (A) relationship name. It is the plural of the child name (hence adding an 's' with 'A' -> 'As') with ' __r ' appended to it.
Thanks.
select Id,(select Id from Opportunities__r) from Custom_Object_c
List<Opportunity> opp=[SELECT Id, Name,Account.Name,Account.Industry,(select Id, Name from Areas_of_interest__r) area from Opportunity ];
system.debug('The '+opp.Areas_of_interest__r);
for(Opportunity o : opp)
{
for(AreaOfInterest__c(Object api Name) are : o.Areas_of_interest__r (The column which are querying inside query)
{
system.debug('The value of opportunity id'+ o.Id);
system.debug('The value of Area of Intrest '+ are.Id);
system.debug('The value of Area of Intrest '+ are.Name);
}
}