I am trying to restore the owner of the case based on partial match, where we select the most recent case that matches the partial match.
This is the query I'm trying to do:
SELECT User.CustomField__c FROM User WHERE User.Id IN ( SELECT OwnerId FROM Case WHERE Case.CaseNumber LIKE '%1026' ORDER BY Case.CreatedDate DESC LIMIT 1)
The following query works on its own, but does not seem happy as part of a subquery:
SELECT OwnerId FROM Case WHERE Case.CaseNumber LIKE '%1026' ORDER BY Case.CreatedDate DESC LIMIT 1
Similarly, if I omit ORDER BY and LIMIT , it works:
SELECT User.NVMContactWorld__NVM_Agent_Id__c FROM User WHERE User.Id IN ( SELECT OwnerId FROM Case WHERE Case.CaseNumber LIKE '%1026')
Order / constraint queries not allowed in SOQL subquery?
To clarify this problem, the scenario I'm dealing with looks like this ...
Salesforce can customize the "display format" for case numbers. If they choose the numbers "4", you get the numbers of such cases as:
You can change the numbers of your numbers to get the numbers of the following cases, as well as the case numbers above ...
I did not want people to be confused by the LIKE operator, the problem is that 001234 and 1234 are different cases, so if the client supplies 1234 and I find two entries, I want to start with the assumption that they are the very last case.
So, consider a LIKE statement or an IN statement containing ('001234', '1234')