I need to query a list of opportunities where AccountId = AccountId AND OwnerId = UserInfo.getUserId, and if that logged-in user has a higher role(manager), they can see their team members' opportunities, but if that user is a member, they can only see their own opportunity.
Now my query is:
select id, name, stagename, closedate, amount from opportunity where AccountId = :AccountId
I want the query to be like this:
select id, name, stagename, closedate, amount from opportunity where AccountId =: AccountId and (OwnerId =: userId or OwnerId =: teamMember1_Id or OwnerId =:teamMember2_Id or... );
The OR condition in the OwnerId will keep extending unless that user is a team member. I have a list of OwnerId, but I don't know how to add them to a query using Apex. Please help.
FYI: This query will show opportunities on the Visualforce page based on which user is logged in.