• Tim Osborn 5
  • NEWBIE
  • -1 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
I have seen threads with dozens of questions about this over the last 6-7 years, all with the answer of "can't be done".  But, I keep hoping that each new version of SFDC might include a way of accomplishing it, so I'll ask the question once again.

I would like to use SOQL to query a parent object based on whether it does or does not have any child records (whether MD or Lookup).

The perfect query would be something like: 
- SELECT Id FROM Account WHERE COUNT(Contacts__r) = 0
or
- SELECT Id FROM Account WHERE Contacts__r.size() = 0
or
- SELECT Id FROM Account WHERE Contacts__r = null

From what I have found in threads as late as 2013, this does not appear to be possible.

Is that still the case in the Summer 2014 release?

It would appear that (for my needs) the best way to execute this type of query would be to:
- SELECT Name, (SELECT name FROM Contacts) FROM Account
- Then programmatically check the size of the returned set of Contacts

Is this my best option?  I know that I could:
- SELECT Id, Name FROM Account WHERE Id IN (SELECT AccountId FROM Contact)
But the actual objects that I want to interogate are more that the 50k limit for this type of query.

Thanks.

Bryan Hunt