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?
Best Answer
As the error message suggests, there is no such column with API name as
Username
onLoginHistory
object (Documentation for LoginHistory at this link). AlthoughUsername
is a field onUser
object but that field cannot be queried fromLoginHistory
object using relationship query.As mentioned,
Username
and all the fields related toUser
cannot be queried from theLoginHistory
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)
Note:
User
object is not a child ofLoginHistory
, you cannot query on User using inner query ofLoginHistory
Select Id, Account.Name FROM Contact