1

I want to do a query like this:

SELECT Id, Name, Email FROM User WHERE Id IN (SELECT OwnerId FROM Opportunity WHERE AccountId = '001610000085XsNAAU' ORDER BY LastActivityDate DESC NULLS LAST Limit 1)

But I have an error:

expecting a right parentheses, found 'ORDER'

Isn't it possible to use ORDER and LIMIT in subqueries?

  • May i know where you are writing this query? – Subhash Jun 16 '16 at 8:39
  • @Subhash I am testing it in Workbench. link – grass Jun 16 '16 at 8:42
0

Try to write the query in 3 steps such as:

List<Opportunity> opps = [SELECT id,OwnerId FROM Opportunity WHERE AccountId = '001610000085XsNAAU' ORDER BY LastActivityDate DESC NULLS LAST Limit 1];

Set<Id> ids= new Set<id>();
for(Opportunity o :opps){
    ids.add(o.ownerId);
}

List<User> users = [SELECT Id, Name, Email FROM User WHERE Id IN : ids]; 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.