I have written a very simple SOQL query in Salesforce but it doesn't work.
SELECT Id, UserId, TerritoryId, IsActive
FROM UserTerritory
WHERE UserId NOT IN (SELECT UserId
FROM UserTerritory
GROUP BY UserId
HAVING COUNT(UserId) > 1)
The query above is throwing the following exception:
- In Developer Console, it shows "Unknown error parsing query"
- In Workbench, it shows:
MALFORMED_QUERY: (SELECT UserId FROM UserTerritory GROUP BY UserId HAVING count(UserId) ^ ERROR at Row:1:Column:114 expecting a right parentheses, found 'GROUP'