You need to sign in to do that
Don't have an account?
Shrey Tyagi
SOQL - OR clause in sub query- Please Help!!!
Need help with following SOQL
Select Id,Name from Opportunity where
name != null
and
(
Id In (Select OpportunityId FROM OpportunityTeamMember where Name LIKE '%shrey%')
OR
(Proposal_Leader__r.Name='Shrey Tyagi')
)
order by Name asc nulls first limit 50
Error : MALFORMED_QUERY: Semi join sub-selects are only allowed at the top level WHERE expressions and not in nested WHERE expressions.
Select Id,Name from Opportunity where
name != null
and
(
Id In (Select OpportunityId FROM OpportunityTeamMember where Name LIKE '%shrey%')
OR
(Proposal_Leader__r.Name='Shrey Tyagi')
)
order by Name asc nulls first limit 50
Error : MALFORMED_QUERY: Semi join sub-selects are only allowed at the top level WHERE expressions and not in nested WHERE expressions.
or without Id In (Select OpportunityId FROM OpportunityTeamMember where Name LIKE '%shrey%') OR
that works fine so the only solution without an aggregate query is two queries (the alternative OR is impossible here directly).
2) An aggregate query uses OpportunityTeamMembers (plural)
Id In (Select OpportunityId FROM is implicit using an aggregate query.
Best regards
Alain
1. All related opportunity team member records: to see id any opportunity exists with such team member or not . That is why I used
Id In (Select OpportunityId FROM OpportunityTeamMember where Name LIKE '%shrey%')
2. A look up field ( looking up to the user ) exists on Opportunity record called Proposal _Leader__c .
So the query should return all opportunity records where either existas a team member by name Shrey or the proposal leader's name is Shrey.
That is why I used : name != null and (condition 1 or condition 2)
Can you help me with this type of query ?
The only solution is two queries.
Using an aggregate query, the filter is not optimized at all as you can see ( name != null means that nearly all the opportunities will be browsed ) but it is interesting to show it for the "theory" only (what could be the alternative for a single query ? there is no optimized one).
Alain
Can you please help me split my query into 2 separate queries? name!=null was just for example.
Select Id,Name from Opportunity where
StageName != 'Closed Won'
AND
Sub_Stage__c='Awarded'
AND
(
Id In (Select OpportunityId FROM OpportunityTeamMember where Name LIKE '%shrey%')
OR
(Proposal_Leader__r.Name='Shrey Tyagi')
)
order by Name asc nulls first limit 50
Thanks a lot for your help.
Regards
Shrey Tyagi
1) First set:
2) Second set:
The problem is the OR with a join that SOQL cannot process.
Alain