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
Michael DsozaMichael Dsoza 

EmployeeNumber field of User object is not accessible

Hi,

Not accessible EmployeeNumber field of User object from Attachment Query whereas Name, Alias are accessible.
Plesae explain why am I not able to access EmployeeNumber.

API Version - 33.0
My Query is - SELECT Id,Name, CreatedBy.EmloyeeNumber FROM Attachment
Error - INVALID_FIELD: 
SELECT Id,Name, CreatedBy.EmloyeeNumber FROM Attachment
^
ERROR at Row:1:Column:17
No such column 'EmloyeeNumber' 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.

Thanks.
Best Answer chosen by Michael Dsoza
surasura
Hi  Micheal ,

I checked on that and even I got the same error , upon further investigation   I found out created by is Polymorphic field which is pointing to more that one type of object 

please refer http://www.tgerm.com/2010/11/no-such-column-on-entity-error.html 

therefore you have to writer seperate query on user object to get the EmployeeNumber field of created by user
 
List<Id> createdUserIds = new List<Id>();
for(Attachment a :[Select Id,Name,createdBy from Attachment])
{
createdUserIds .add(a.createdBy);

}


List<user> createdUsers = [Select Id,EmployeeNumber from User where Id IN:createdUserIds];

hope this helps

All Answers

surasura
Are you referring to standard attachment object if so there is no such field called EmloyeeNumber in it and we cant add custom fields to attachment object , could you tell me in what object EmloyeeNumber field reside.

fyi : every custom fields api name is differnt from its label .
      Saleaforce appends __c to fields label and replace spaces with when generating api names
     eg: if field label is Employee Number api name would be Employee_Number__c

 
Michael DsozaMichael Dsoza
@sura, thanks for reply.

I am using standard Attachment object but I am referring createdBy User field and trying to get createdBy user's EmployeeNumber field. Which is also standard field of User object. I am able to access Id, Name, Alias of User field using createdBy.Id, createdBy.Name, createdBy.Alias but whenever I try createdBy.EmployeeNumber field then I get error 'No such column on user entity'. 

Is there any security restriction on EmployeeNumber field of User object ?? OR
Is there any API version issue ?? (currently using 33.0 API version) 

Thanks.
surasura
Hi  Micheal ,

I checked on that and even I got the same error , upon further investigation   I found out created by is Polymorphic field which is pointing to more that one type of object 

please refer http://www.tgerm.com/2010/11/no-such-column-on-entity-error.html 

therefore you have to writer seperate query on user object to get the EmployeeNumber field of created by user
 
List<Id> createdUserIds = new List<Id>();
for(Attachment a :[Select Id,Name,createdBy from Attachment])
{
createdUserIds .add(a.createdBy);

}


List<user> createdUsers = [Select Id,EmployeeNumber from User where Id IN:createdUserIds];

hope this helps
This was selected as the best answer
Michael DsozaMichael Dsoza
Thanks sura...Information given by you helped me. :) :) :)

Regards,
Micheal.