I am getting error 'No such column 'AccountNumber' on entity 'Name' when i tried to execute the following query,

select parent.AccountNumber, parentid, subscriberid from EntitySubscription where parent.type='account'

How to get AccountNumber from this query? Please suggest.

1 Answer 1


You need to use TYPEOF to get at this data (currently only a developer preview). If you need this for production code, use two queries instead of one.

select id, typeof parentid when account then parent.accountnumber end from entitysubscription where parent.type = 'account'
  • when i try to use the accountnumber using this statement "mapES.put(es.parent.AccountNumber,es)" i am getting an error "Invalid field AccountNumber for SObject Name". Any suggestions please. I am using developer edition.
    – Bforce
    Commented Sep 11, 2014 at 17:03
  • 1
    That's because Parent is an SObject, so you'd have to: mapES.put((String)es.parent.get(Account.AccountNumber), es) (approximately).
    – sfdcfox
    Commented Sep 11, 2014 at 17:06
  • This is a fantastic, awesome solution @sfdcfox. Thanks again.
    – Bforce
    Commented Sep 11, 2014 at 17:08
  • hi @sfdcfox, i got run time error now System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Account.AccountNumber. Any thoughts please?
    – Bforce
    Commented Sep 11, 2014 at 18:40
  • Odd. I'll try it out.
    – sfdcfox
    Commented Sep 11, 2014 at 18:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .