function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
GregWaxGregWax 

selecting accounts with owner id = current user or current user is a teammember for the account

I need to select all acounts that the current user is the owner or accounts where the current user is in the accountteammember.

 

 

This is the code that I am testing in ForceIDE

 

select a.id, a.ownerid, a.name from account a where a.ownerId  =  '0056000010dFwAAI' or  a.id in (select b.accountid from accountteammember b where b.userid = '00560000001188cAAA' )

 

Ideally this is what I want to use:

select a.id from accounts a where a.OwnerId = \''+UserInfo.getUserId()+'\' or  a.id in ( select accountID from accountteammember where  userid  =  \''+UserInfo.getUserId()+'\'

 

I receive the follwing error message "Malformed Query:  Semi join sub selects are not allowed with the 'or' operator.

 

I would appreciate any guidance.

 

Thank you.

FromCRMWonderlandFromCRMWonderland
If in your org, each account has at least one accountTeam member then you can use following query:- Select a.Account.OwnerId, a.AccountId, a.userid From AccountTeamMember a where a.userid = '00560000001188cAAA' or a.Account.OwnerId = '0056000010dFwAAI' If there are any accounts without any teammember, I guess this query will not give proper result.....in that case you need to fire seperate query on account with single condition to check owner. --- alok
Idd BaksheeshIdd Baksheesh

Aaah buddy, you can add subquery after table name. Add it before. Or better way is use 2 quries and use SET