[SalesForce] How to query Related Opportunities related List in Account

This question may seem simple to anybody there. I've been searching for a way(to no avail) on how to query the related Opportunities in Account. This isn't the normal Opportunity related list.

So for example ACME account has 'Opportunities' related list which has 4 records and another related list named 'Related Opportunities' which has 50 records. I wanted to query those 50 'Related Opportunities' records. I'm not certain if this is a back end object but I can't seem to find it.

Any help would be appreciated.

Best Answer

Freya

another option (assumming the relationship name from Account -> Opportunities is OpportunitiesAsDistributor__r)

Account a = [select Id, Name, (select Id, Name from OpportunitiesAsDistributor__r) 
  from Account where ID = :someAccountId limit 1]

and you can loop through the Opportunities by

for (Opportunity o : a.OpportunitiesAsDistributor__r) {
  // do work
}