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 Answer 1

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 ...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .