+ Start a Discussion
SF-NewBieSF-NewBie 

LoginHistory API - UserName Field

Hi,

 

I am accessing Login History Object using CuRL to API v27.0.  curl https://na15.salesforce.com/services/data/v20.0/sobjects/LoginHistory -H 'Authorization: Bearer access_token' -H "X-PrettyPrint:1". I was hoping to get all the fields as I would get  by downloading Excel sheet by going to Manage Users | Login History.

 

But the API call could yield only USERID as opposed to USERNAME as I would get by downloading Excel Sheet.

 

1) Is this a limitation of API or am I missing anything??

2) Is there a way to map USERID -> USERNAME ??

 

Any help would be appreciated. 

Best Answer chosen by Admin (Salesforce Developers) 
Avidev9Avidev9
User Object will have "Id" field, you should be mapping the LoginHistory Object's "UserId" with User Object's "Id" Field.

All Answers

Avidev9Avidev9

These are the fields that you should be able to access uisng API http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_loginhistory.htm

 

 

I guess you can include some thing like User.Name in your query, the object seems to haev relationship with user

SF-NewBieSF-NewBie

Thanks Avi. In the list of fields given at http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_loginhistory.htm, I cannot see USERNAME, so I was wondering whether Salesforce does not open it??

 

I tried giving UserName, User.Name in my queries but it does not return anything. I would have hoped salesforce did better job with exposing all fields in API, but would there be a way to atleast map UserID -> UserName??

Avidev9Avidev9
Well that wont be straight forward.
1. From first call collect all the user ids
2. Query using these userid to SF and map it
SF-NewBieSF-NewBie

I am to able to do step 1. But, it looks like SF doesn't provide any handle for mapping UserID to UserNames. Any idea?

Avidev9Avidev9
You have to basically execute a SOQL query to the Salesforce User Object whihc contains the User detail
Avidev9Avidev9
User Object will have "Id" field, you should be mapping the LoginHistory Object's "UserId" with User Object's "Id" Field.
This was selected as the best answer
Jing HeJing He
LoginHistory has a UserId field under LoginHistory has “referenceTo” attribute whose value is “User”.  If I check out the “Child Relationships” under User, there is one entry for LoginHistory,  Why there is NO "relationshipName" attribute for UserId field under LoginHistory as I assume for each relationship there must be a relationshipName?