0

I have process in salesforce in such a way opportunity we can relate this opportunity to this lookup field parent_opportunity__c . Which relates opportunity to other parent opportunity.

I want to write a query parent to child :

select id,(select id from opportunity where parent_opportunity__c!=null) from opportunity where parent_opportunity__c=null

I have worked with different scenarios i cant able to crack it

select id,name,(select id,name from parent_opportunity__r) from opportunity this is showing error and

select id,name,(select id,name from opportunity) from parent_opportunity__c this is also error

  • can you please check what is the relationship name used on the parent_opportunity__c field and try using that? for example: select id,name,(select id,name from relationshipNameOnTheLookupField) from opportunity – Rajiv Bhatt Apr 14 '15 at 6:05
  • relationship name is Opportunities – Karthika Ram Apr 14 '15 at 6:08
  • still i am getting th error – Karthika Ram Apr 14 '15 at 6:09
  • select id,name,(select id,name from opportunities) from opportunity ^ ERROR at Row:1:Column:37 Didn't understand relationship 'opportunities' 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. – Karthika Ram Apr 14 '15 at 6:09
1

You need the PLURAL of the parent_opportunity object name.

Given that your object is called parent_opportunity__c, it's likely your relationship is called something like child_opportunities__r. You can check this on the lookup field that defines this relationship.

Once you have that, use this field in your query - it should work.

You can see in the image of the definition of a lookup that the relationship from parent to child is Screenings__r and from child back up to Opportunity is Opportunity (as there is only one)

enter image description here

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.