function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
OmarOmar 

Login History

hi,
Does the salesforce store the login histroy of a user??
For example, when i log in, i need to see what was the last time i logged in. Although a method is provided with the User class getLastLoginDate(). But wen i log in, my last login date changes to the current loggin time. In short, i want to access my previous loggin date/time.
kindly help me in this regrd.
thanks
Omar Altaf
SuperfellSuperfell
Login History is tracked and available for viewing + download to CSV from the setup part of the application. This data though is not currently API exposed.
heiriticheiritic

Hi,

 

I want to ask a question regarding this matter. Is it possible right now for the API 15 to get the login history from API ?

 

 

regards,

edwin

SuperfellSuperfell
No.
mrizmriz
Latest release of salesforce has an object name LoginHistory using which you can access the login history of any user.

For a particular user, you need to mention userID in SOQL query:
 
public void someFunction(){
    LoginHistory logH= [select field1,field2,... from LoginHistory where userID='some_User's_id' limit 1];
    // for one record.
    // for multiple records you can store results in a list.
}

In case you want to get login details of current user then use following line instead.
LoginHistory logH=[select field1,field2,... from LoginHistory where userID=:userInfo.getUserID()];


for detailed documentation, navigate to following page:
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_loginhistory.htm