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
ShamilShamil 

BUG in SOQL? Invalid SOQL to get Task Owner information

I am trying to get Task Owner's Mobile Phone number using the following SOQL:

 

Select  t.Owner.MobilePhone from Task t

 

When I try to execute it I get an error message:  "No such column 'MobilePhone' on entity 'Name'"

 

The error shows up for some other columns too, e.g. CallCenterId (of User object), while some I am able to get data for some other columns, such as Name, LastName, etc.

 

Why is that?

 

 

 

Message Edited by Shamil on 07-02-2009 10:15 AM
Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell
Owner on Task is a polymorphic relationship (i.e. to can be a foreign key to different types), for these types of relationships only a subset of data of the related object is exposed, these are fields defined on the Name entity, including firstName, lastName & phone, but not all fields from user. From the schema you can see this because the ownerId field has the isNamePointing property set to true. There's also a give-away in the error message where it says the field is not valid for the Name entity. This is all covered in the SOQL-R section of the API documentation.

All Answers

sforce2009sforce2009

It normally works from apex or VF Class. i am not sure check out. but it definitely not works from apex explorer or salesforce

schema in eclipse

AlsoDougAlsoDoug
I tried it yesterday in the schema in Eclipse and was getting the same issue.
ShamilShamil
The query doesn't work both in Apex and through API.
QuickDEVQuickDEV

Try this:

 

Select t.Owner.Phone  From Task t

 

 

Thanks

ShamilShamil

The thing is that there are 2 fields on User object: Phone and MobilePhone.

I need MobilePhone. 

QuickDEVQuickDEV

Oops...No luck for me too

 

I could see the field "Cell" (for Mobile phone), but query does not work.

ShamilShamil

Ron, thanks for looking into this. What you're saying makes sense, but there are couple of things I don't undertand:

1. Phone and MobilePhone fields have exactly the same attributes:

- createable

- filterable

- nillable

- updateable

 

... and the following SOQL works:

Select  t.Owner.Phone from Task t

 

that is Phone is queryable

 

2.Some other fields, such as 'Name', 'LastName' having the following attributes:

- filterable

- sortable

 

are still queryable with SOQL queries, such as:

Select t.Owner.Name from Task t 

 

 

 

3. Side question - not really for you, but still - why would Apex Explorer and Schema browser in the IDE let a user create invalid SOQL statements?

 

 

Thanks,

Shamil

SuperfellSuperfell
Owner on Task is a polymorphic relationship (i.e. to can be a foreign key to different types), for these types of relationships only a subset of data of the related object is exposed, these are fields defined on the Name entity, including firstName, lastName & phone, but not all fields from user. From the schema you can see this because the ownerId field has the isNamePointing property set to true. There's also a give-away in the error message where it says the field is not valid for the Name entity. This is all covered in the SOQL-R section of the API documentation.
This was selected as the best answer
Ron HessRon Hess
Thanks Simon!
sandipmsandipm

hey shamil,

did you resolve this?

 

regards,

Sandip 

ShamilShamil
Since this info cannot be obtained in 1 SOQL call, you'll need to make a separate SOQL request to objects that can be Task Owners
sandipmsandipm
yes I got it afterwords I did it same way you are suggesting...