Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So this would be possible with a roll-up summary, but since there's a limit on the number of these available, I'm trying to accomplish it without the roll-up summary field.

Via SOQL I need to get a list of parent records (for example Accounts) which have 0 children (for example Contacts).

Ideally it'd be something along these lines, but alas no luck:

select Id
from Account
where (select count() from Contacts) = 0


share|improve this question

You can check for parent Id of the child records to get this.

SELECT Id, Name FROM Account WHERE Id NOT IN (SELECT AccountId FROM Contact)
share|improve this answer
This answer was posted about 10 minutes after I posted my answer... – Ray Dehler Jul 18 '14 at 21:04
This is normally happening when people helping the community in parallel with different questions. While replying to you some others putting comments for theirs one. After looking at them and come back, hit enter for yours some similar answers can be there.. – highfive Jul 19 '14 at 17:44
up vote 2 down vote accepted

Found it!

select Id
from Account
where Id not in (select AccountId from Contact)


share|improve this answer
What happens when there are a large # of contacts (lets say a million). Won't this query hit limits – NSjonas Mar 29 at 22:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.