I am trying to access Username field (which is present in User Object) Using LoginHistory Object as follow:


but is shows below error:

[{"message":"\nSELECT Username FROM LoginHistory\n ^\nERROR at Row:1:Column:8\nNo such column 'Username' on entity 'LoginHistory'. 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.","errorCode":"INVALID_FIELD"}]**

also tried nested SOQL Query as :


then also getting error.

How do I fix this error?

2 Answers 2


As the error message suggests, there is no such column with API name as Username on LoginHistory object (Documentation for LoginHistory at this link). Although Username is a field on User object but that field cannot be queried from LoginHistory object using relationship query.

As mentioned, Username and all the fields related to User cannot be queried from the LoginHistory object, there is an idea here for this specific requirement which you can up vote if you wish to and use the workaround mentioned at that link.

Excerpt from the above mentioned link (Workaround)

As a workaround you can run a "User" report and add all the fields from User object that you may want to include(make sure you add Login Date/Time field).


  • Regarding querying the related fields, you need to use the relationship queries for which you can refer this link.
  • As User object is not a child of LoginHistory, you cannot query on User using inner query of LoginHistory
  • You cannot access parent's field directly in your SOQL query, you will have to use the relationship query eg : Select Id, Account.Name FROM Contact

You'll need to make-do with two separate queries. There's equally no way to reverse it because the related list doesn't have name either.

  • can you please explain it with an example. Commented Apr 16, 2019 at 6:17

You must log in to answer this question.

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