function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Darla.ax69Darla.ax69 

Query for null parent ID

Hello,

I need to query for all accounts without a parent ID. I tried this query:

select Id from Account where ParentId = null

And there are no results. I'm guessing maybe I have to do something different since the type of ParentId is a reference?

Any help is appreciated,

=> Darla
benjasikbenjasik
Try this:

Select name from Account where ParentId = '000000000000000'

Foreign keys that are empty typically point to the "Empty Key".
darozdaroz

Just a quick note to point out that

  1. This is incredibly useful and can we get the API docs updated to include this useful tidbit?
  2. It only works with you use 15 0's, not 18 0's, you'd have to convert the 15 character ID of '000000000000000' to an 18 character ID of '000000000000000AAA' to get that to work...

Thanks Benji!!!

benjasikbenjasik
We will be updating the docs. This post made us realize this isn't documented, nor is it consistent. If you query on 15 0's (the empty key), you get null back for the actual value. We're trying to determine the best approach going forward.

Thanks.
darozdaroz

Just another part about inconsistency... (Forgive any errors blow - I'm off the cuffing it)...

This doesn't work: Select Id, ParentId From Account Where ParentId = null

This does work: Select Id, ParentId From Account Where ParentId = '000000000000000'

 

This doesn't work: Select Id, RecordTypeId From Account Where RecordTypeId = '000000000000000'

This does work: Select Id, RecordTypeId From Account Where RecordTypeId = null

 

Thought I'd point this one out if you want to update the docs while you're at it.

benjasikbenjasik
We're going to make null work across all versions

Thanks