You need to sign in to do that
Don't have an account?
FSamorgan
How to query owners for opportunities including opportunities that have split owners
I am trying to write an soql that queries owners in opportunities as well as including the opportunities that have those split owners.
For example if I want Opportunities that Angela and Bob own I write:
SELECT Id from Opportunity where OwnerId in (:AngelaId, :BobId);
but I also want to include opportunities that Angela and Bob own as split owners. How do I do this?
a bad example to try to show what I want:
SELECT Id from Opportunity where OwnerId in (:AngelaId, :BobId) or OpportunitySplit.SplitOwnerId in (:AngelaId, :BobId);
For example if I want Opportunities that Angela and Bob own I write:
SELECT Id from Opportunity where OwnerId in (:AngelaId, :BobId);
but I also want to include opportunities that Angela and Bob own as split owners. How do I do this?
a bad example to try to show what I want:
SELECT Id from Opportunity where OwnerId in (:AngelaId, :BobId) or OpportunitySplit.SplitOwnerId in (:AngelaId, :BobId);
Like -
SELECT OpportunityId FROM OpportunitySplit WHERE SplitOwnerId IN ('BobId', 'AngelaId');
Now you can iterate over the query results to collect all OpportunityIds in a Set and use it in another query on Opportunity/other objects.
You may also make it a relationship query, if that may fulfill your use case like -
SELECT OpportunityId, SplitAmount, SplitPercentage, Opportunity.Name, Opportunity.Amount FROM OpportunitySplit WHERE SplitOwnerId IN ('BobId', 'AngelaId');