I am doing subquery Of Opportunities on Contact as follows:-

Select id,(select id from Opportunities) from Contact where id in (select ContactId from OpportunityContactRole)

I know this will return those Contacts which have at least one related opportunity. But what I can see, Those Opportunities which are Closed are not coming in the result but ContactId is coming.

Later, I found this is happening for those Opportunities whose contact roles have not checked for primary=true.

Can You make me understand this behaviour?

1 Answer 1


My answer for your question: I think/suspect that the sub-query from contact to child opportunities requires isPrimary on the OpportunityContactRole for that downwards traversal.

As a side note, If you later decide that you want to query all opportunities that have any opportunity contact role defined (regardless of isPrimary or not) then use SELECT ID from Opportunity where ID IN (Select OpportunityID from OpportunityContactRole)

You must log in to answer this question.

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