4

I simply cannot understand the reason why I am getting this below error.

17:16:15.106 (1106785435)|SYSTEM_METHOD_EXIT|[29]|system.UserInfo.getUserId()
17:16:15.107 (1107062779)|EXCEPTION_THROWN|[29]|System.QueryException: No such column 'Username' on entity 'User'. 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.
17:16:15.107 (1107185681)|FATAL_ERROR|System.QueryException: No such column 'Username' on entity 'User'. 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.

Trigger.AuditUserTrigger: line 29, column 1
17:16:15.107 (1107198322)|FATAL_ERROR|System.QueryException: No such column 'Username' on entity 'User'. 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.

I have got a before update trigger on User which is querying for the UserName field on the User object.

User user = [Select Id, Username From User u Where u.id =: UserInfo.getUserId()];

I also receive an error in the logs whenever I open the developer console.

14:05:11:380 FATAL_ERROR System.SObjectException: Invalid field ManagerId for User
  • The queries run fine in the Query Editor. – Chetan Gupta Sep 29 '14 at 8:47
  • Post the complete logic atleast method. – Ashwani Sep 29 '14 at 8:51
2

This is almost certainly a permissions issue. The user performing the transaction doesn't have access to the User.Username field.

Does their Profile have the View Setup and Configuration permission?

Are you dealing with a Communties / Partner Portal User?

One oddity from the User documentation:

Usage

Use this object to query information about users and to provision and modify users in your organization. Unlike other objects, the records in the User table represent actual users—not data owned by users. Any user can query or describe User records.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.