1

The following query is working, but I am not sure why:

select Id, (SELECT id FROM opportunities ) from Contact

I was always under the impression that there was no relationship between the contact and opportunity besides the opportunity contact role. Is there an edge case that I am not accounting for? We have a lookup to contacts on the opportunity - is that why this query is working?

1 Answer 1

4

There's actually a standard field called Opportunity ContactId. This is where the data is coming from. I'm not sure why this field isn't in the documentation, but I found this field in my org, and the query also worked.

Edit: Per comments, this field appears to be deprecated and/or unused. I also could not find it in Setup, although it does appear in the Developer Console. You shouldn't try to use this field.

4
  • 1
    I was under the impression this was a backend field SF was going to use many moons ago but then decided to deprecate in a maintenance release. Seems that is not the case. I'd highly recommend some good unit testing to ensure the next (or any future) release does not screw up the SOQL.
    – TSmith
    Commented Mar 16, 2020 at 17:40
  • @TSmith I couldn't find a link on that. I wonder if we could find anything on it. I was surprised to find it existed in the first place. It doesn't show up in Setup, but does appear in the Developer Console (Ctrl-Shift-O, Opportunity.obj).
    – sfdcfox
    Commented Mar 16, 2020 at 17:41
  • 1
    @sfdxfox a blog post with a Force.com Product Manager comment might help. Although, it is quite old.
    – TSmith
    Commented Mar 18, 2020 at 13:07
  • @TSmith Oh, that's a great find. I presume this probably just got sat on the backburner, since there's ways to accomplish this task using automation.
    – sfdcfox
    Commented Mar 18, 2020 at 13:27

You must log in to answer this question.

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