0

When I was checking the 'Account Name' field in Contact Object, it is appearing as a 'Lookup(Account)'. Account is parent and contact is child, I know those relationships and behavior.

parent to child query
ex: account ac =[select id,name ,(select id,name from contacts) from account]; same like

contact is child and Opportunity parent but query from different

 List<contact> consobj=[SELECT id,firstname,(SELECT OpportunityId FROM OpportunityContactRoles) ,lastname FROM contact ];

What is the difference between account/contact and contact/Opportunity?

1 Answer 1

1

In First Query:

account ac =[select id,name ,(select id,anme from contacts) from account];

Contact have lookup to Account so you can Query like that

In second Query :

 List<contact> consobj=[SELECT id,firstname,(SELECT OpportunityId FROM OpportunityContactRoles) ,lastname FROM contact ];

As you said Contact is not child of opportunity but OpportunityContactRole is child of both Account and opportunity. Here OpportunityContactRole is junction object to achieve many to many relationship between Opportunity and Contact.

For more on junction objects read https://help.salesforce.com/articleView?id=relationships_manytomany.htm&type=0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .