function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mike SummittMike Summitt 

SOQL Syntax in developer console

I've created a SOQL statement designed to locate accounts for which the primary contact cannot be determined, that is, accounts where there is more than one contact, but the accountcontactroles do not specify any primary.  The SOQL won't parse, says "Unknown parsing error".  Can anyone see what's wrong with it?

SELECT Id
FROM Account
WHERE Id IN (SELECT Account FROM Contact GROUP BY Account HAVING Count(Id) > 0)
AND Id NOT IN (SELECT AccountID Id FROM AccountContactRole WHERE IsDeleted = false and IsPrimary = true)
pconpcon
From what I can see, you get that error when you use having in a subquery.  I don't know if it's a limitation or a bug.  I would file an issue with Salesforce to see which it is.