I have a custom object called Sport, and sport has an Owner like every other object. When I do a Query on Sport:

Map SportMap=new Map([SELECT Id, OwnerId, Owner.Email FROM Sport__C Limit 50000]);

It works just fine, but as soon as I change Owner.Email to Owner.NewRole__c which is a custom field on the user record, it gives me an error message: No such column 'NewRole__c' on entity 'Name'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

Why is that and how can I fix it? Thanks!


1 Answer 1


The Owner field is likely a polymorphic relationship field. This means the relationship can point to more than one object (i.e. User and Queue). If you happen to have the Polymorphism feature enabled in your org, you can use the TYPEOF operator like this:

  TYPEOF Owner
    WHEN User THEN NewRole__c
FROM Sport__c 
LIMIT 50000

Otherwise, you'll need to query out the users separately and perform a secondary query to get the related user data.

More info can be found here. You can also request to be included in the polymorphism beta by submitting a case to Salesforce.

  • Awesome help Kevin, I didn't know about TYPEOF, I just submitted a case to Salesforce for them to enable this feature. Let's say this works, and I get a List of Sports__c, how do I access the NewRole__c if my list is a list of Sports?
    – Leo
    Commented Oct 8, 2015 at 19:01
  • I believe you can access it with regular dot notation. I'm not sure though. Let us know! Commented Oct 13, 2015 at 12:07
  • 1
    Well since TYPEOF is not ready for Production and that is where I need the code to go, I just created a Set<Id> with those IDs and then I created a Map of Users. That worked and I was able to deploy my code. Thanks for your help!
    – Leo
    Commented Oct 14, 2015 at 16:07

You must log in to answer this question.

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