You need to sign in to do that
Don't have an account?
Javier Maldonado
Query all child records contained in to an opportunity
I'm trying to query all related record in a child list from opportunity object, but I've not achieved this:
Parent Object: Opportunity
Child Object: Opportunity_Product__c (Custom Object)
Fields: Product_Description1__c and Product_Dimension__c
Master-Detail(Opportunity): Opportunity__c
So far, I have:
Select Id, Name,
(
Select Id, Opportunity__r.Opportunity__c,
Opportunity__r.Product_Description1__c,
Opportunity__r.Product_Dimesion__c
from Opportunity_Product__c
)
from Opportunity where id = '0061b000002DjSCAA0'
Any HELP, will appreciated... Thanks
Parent Object: Opportunity
Child Object: Opportunity_Product__c (Custom Object)
Fields: Product_Description1__c and Product_Dimension__c
Master-Detail(Opportunity): Opportunity__c
So far, I have:
Select Id, Name,
(
Select Id, Opportunity__r.Opportunity__c,
Opportunity__r.Product_Description1__c,
Opportunity__r.Product_Dimesion__c
from Opportunity_Product__c
)
from Opportunity where id = '0061b000002DjSCAA0'
Any HELP, will appreciated... Thanks
You need to read the Relationship Queries -
Try this one -
Select Id, Name, (Select Id, Product_Description1__c, Product_Dimesion__c from Opportunity_Products__r) from Opportunity where id = '0061b000002DjSCAA0'
Pls, let me know, if it solves your problem.
Thanks,
Sumit Kumar Singh
All Answers
You can try this -
You can go to "Opportunity__c" field and look for "child Relationship Name" ; whatever the name is append "__r" in the last. The nested SOQL is accessed with the Child relationship name.
Select Id, Name,
(
Select Id, Opportunity__r.Opportunity__c,
Opportunity__r.Product_Description1__c,
Opportunity__r.Product_Dimesion__c
from Opportunity_Product__r
)
from Opportunity where id = '0061b000002DjSCAA0'
Hope it will help you.
Thanks,
Sumit Kuamr Singh
So just give a try using below code.
[Select Id, Name,
(
Select Id, Opportunity__r.Opportunity__c,
Opportunity__r.Product_Description1__c,
Opportunity__r.Product_Dimesion__c
from Opportunity_Products__r
)
from Opportunity where id = '0061b000002DjSCAA0']
but I don't know why you are query values in the Master Object Opportunity from child object ?
You can query directly
[Select Id, Name, Opportunity__c,Product_Description1__c, Product_Dimesion__c,
(
Select Id
from Opportunity_Products__c
)
from Opportunity where id = '0061b000002DjSCAA0']
But I'm still getting the same error...
From Sumit code:
from Opportunity_Product__r
^
ERROR at Row:8:Column:6
Didn't understand relationship 'Opportunity_Product__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
From Shaswanthnaga code:
Opportunity__r.Opportunity__c,
^
ERROR at Row:4:Column:1
No such column 'Opportunity__c' on entity 'Opportunity'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.
Answering your question...
I'm trying to create a RollUp Text field from all Opportunity_Product__c object records, and update RollUp_Product_Description field (located in Opportunity) and separated by ";", the only way to achieve this is doing a Trigger from the child object (Opportunity_Product__c)...
In other words, trying to create a RollUp Text field
Any hand, will be appriciated...
Javier
Did you check the relationship name?
This is from Opportunity_Product__c object
here, the relationship name is "Opportunity_Products", so the relationship name would be "Opportunity_Products__r",
try this one -
Select Id, Name,
(
Select Id, Opportunity__r.Opportunity__c,
Opportunity__r.Product_Description1__c,
Opportunity__r.Product_Dimesion__c
from Opportunity_Products__r
)
from Opportunity where id = '0061b000002DjSCAA0'
Nothing!!!
Opportunity.Opportunity__c,
^
ERROR at Row:4:Column:1
Didn't understand relationship 'Opportunity' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
You need to read the Relationship Queries -
Try this one -
Select Id, Name, (Select Id, Product_Description1__c, Product_Dimesion__c from Opportunity_Products__r) from Opportunity where id = '0061b000002DjSCAA0'
Pls, let me know, if it solves your problem.
Thanks,
Sumit Kumar Singh
It's working now...