0

The Master object Custom_Opportunity__c have a master-detail relationship on Product__c. Normally there are many Product__c records under one Custom_Opportunity__c record. Every time I use Custom_Opportunity__c.Product__r in my VF page, it shows the newest record.

Is there a way for me to query all the children under this Custom_Opportunity__c and let the user to choose which child they want to work on? In the object layout page, all the children can be seen. However, now I want to show them in a VF page. And my major issue here is to get all children records once together.

Thanks

0

Probably the easiest way would be to query all products based on your custom opportunity id. For example:

SELECT Id FROM Product__c WHERE Custom_Opportunity__c = :yourCustomOpportunityId

This will return you all products that are children of the given custom opportunity

| improve this answer | |
0

You can try to make parent-child SOQL in controller at the time of page load (constructor)

ex: Custom_Opportunity__c co = [Select id,(select id, fields__c from Product__r) form Custom_Opportunity__c where id=: oppid];

Make sure that "Product__r" is the child relationship name.

Hope it helps you!!

| improve this answer | |
  • The child relationship name is Loan_Product__r. I tried the SOQL like – Yifei Pei Apr 6 '16 at 5:39
  • Select id,(select id, fields__c from Loan_Product__r) from Custom_Opportunity__c where id= 'a0EN0000005oBXj' – Yifei Pei Apr 6 '16 at 5:40
  • It says Didn't understand relationship 'Loan_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. – Yifei Pei Apr 6 '16 at 5:40
  • Please go to the Loan Object. Go the relationship field that links with Opportunity. Click on the field and it will show a label "Child relationship name". The Child relationship is differ from the field API name. Also. append "__r" in the child relationship name present in the field. For ex: if it is load_products then use "loan_products__r" in the SOQL – userRg Apr 6 '16 at 6:06
  • You can try select id, field__c from Loan_Product__c where Custom_Opportunity__c = 'a0EN0000005oBXj' Custom_Opportunity__c in this case would be the field on Loan_Product__c that stores master record reference – o-lexi Apr 6 '16 at 6:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.