Search code examples
salesforcesoqloql

Hierarchial SOQL Query


Does anyone know how to retrieve the hierarchical model of a account based on it's id?

I tried using this query but all i got is the first set of child nodes.

select a.Name,a.parentId,a.ownerid,a.id from  Account a where Parent.id ='00711314'

Solution

  • SOQL does not support hierarchical retrieval, you have to retrieve level by level, for each level generate a list of id's and then retrieve next level using in <list> where operator.

    Keep in mind though that governor limitations apply and if you have large trees you'll run into a limit quite easily.