• vishnu nv
  • NEWBIE
  • 10 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
Hi, 
  I have used below SOQL query for calculating the No of days in the stage.

SELECT name, StageName from opportunity WHERE isClosed=false AND ((StageName ='Validate' AND Id in (SELECT opportunityId from opportunityHistory WHERE StageName ='Validate' AND CreatedDate=LAST_N_DAYS:20)) OR (StageName ='Connect' AND Id in (SELECT opportunityId from opportunityHistory WHERE StageName ='Connect' AND CreatedDate=LAST_N_DAYS:20)) OR (StageName ='Negotiate' AND Id in (SELECT opportunityId from opportunityHistory WHERE StageName ='Negotiate' AND CreatedDate=LAST_N_DAYS:20)))

But its not working , as it has some limitations. 

Can you please help
Hi, 
  I am trying to write SOQL for below case but facing  issue "Semi join sub-selects are only allowed at the top level WHERE expressions and not in nested WHERE expressions".

Use case is to retreive the opportunity where Amount > 1000 (OR) OpportunityFieldHistory where FIELD='StageName' AND CreatedDate  LAST_N_DAYS:14.

My Query:

SELECT Id, Name from opportunity where  Amount > 1000 OR Id IN(SELECT OpportunityId from OpportunityFieldHistory WHERE Field='StageName' AND CreatedDate=LAST_N_DAYS:14))

Can you please help, how this can be acheived.
Hi,

I am trying to retrieve all the managers from the account with the below SOQL query.

SELECT Name FROM User WHERE ManagerId  IN (SELECT ManagerId  FROM User WHERE ManagerId !=NULL)

But i am facing error :
The inner and outer selects should not be on the same object type

Do we have any other alternatives ?
Hi, 
  I am trying to write SOQL for below case but facing  issue "Semi join sub-selects are only allowed at the top level WHERE expressions and not in nested WHERE expressions".

Use case is to retreive the opportunity where Amount > 1000 (OR) OpportunityFieldHistory where FIELD='StageName' AND CreatedDate  LAST_N_DAYS:14.

My Query:

SELECT Id, Name from opportunity where  Amount > 1000 OR Id IN(SELECT OpportunityId from OpportunityFieldHistory WHERE Field='StageName' AND CreatedDate=LAST_N_DAYS:14))

Can you please help, how this can be acheived.