0

I'm currently trying to write a SOQL Query to pull all Accounts that have < 5 related Contact objects AND No related ts2__Placement__c objects (custom object).

I have successfully been able to pull all Accounts that have < 5 related Contact objects using below:

Select AccountId, Count(Id)  from Contact group by AccountId having count(Id) > 5

However, I'm having trouble with how the custom object relates into that query. I assume it'll have to nest as a sub-query.

1

You can add a WHERE Clause using a Left Inner Join (actually I guess it would be a Left Anti Join) here:

SELECT ...
FROM Contact
WHERE Id NOT IN (
    SELECT Contact__c FROM My_Object__c
)
GROUP BY ...
HAVING ...

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.