0

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

SELECT+Username+FROM+LoginHistory

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 :

SELECT+CountryIso,(SELECT+Username+FROM+User)+FROM+LoginHistory+limit+10

then also getting error.

How do I fix this error?

4

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).

Note:

  • 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
0

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. – chintamani Sahu Apr 16 at 6:17

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.