You need to sign in to do that
Don't have an account?

Apex Controller: Combine two lists
Hello,
I am trying to create a visualforce page that displays all of the current User's Opportunities. I would like to include Opportunities that they own AND all Opportunities where they are a member of the OpportunityTEam.
My first attempt was to do a query like this:
MyOpTeam =[SELECT id, Record_Type_Name__c, Name, StageName, Amount, Owner.Id FROM Opportunity WHERE id IN (SELECT OpportunityId FROM OpportunityTeamMember WHERE (UserId=:UserInfo.getUserId() )OR (Opportunity.OwnerId=:UserInfo.getUserId())];
*** PROBLEM: this only pulled opportunities that had team members. Any opportunities that I owned that did not have a team member record were excluded.
Could anyone look at my current code and tell me how I can go about getting these two SEPARATE queries into one list?
public class Oppsownerteam { public Oppsownerteam(ApexPages.StandardController controller) { } Id Mouse = Userinfo.getUserId(); public List<Opportunity> MyOwnedOpps; public List<Opportunity> MyTEamOpps; Public Integer Get MyOwnedOpps() { MyOwnedOpps =[SELECT id, Record_Type_Name__c, Name, StageName, Amount, Owner.Id FROM Opportunity WHERE ownerid =:Mouse]; return MyOwnedOpps; } Public List<Opportunity> GetMyTEamOpps() { MyTEamOpps =[SELECT id, Record_Type_Name__c, Name, StageName, Amount, Owner.Id FROM Opportunity WHERE id IN (SELECT OpportunityId FROM OpportunityTeamMember WHERE UserId=:Mouse)]; return MyTEamOpps; } }
You also want to be careful in your initial queries that you dont pull some of the same opportunities in each list, then it would show up twice.
All Answers
Could you add another list then aadd both lists to that or add the second list into the first?
Option 1:
or
Option 2:
You also want to be careful in your initial queries that you dont pull some of the same opportunities in each list, then it would show up twice.