Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

Ideas?

share|improve this question

2 Answers 2

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 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 at 17:44
up vote 1 down vote accepted

Found it!

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

Thanks!

share|improve this answer

Your Answer

 
discard

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.