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
Ankit Agarwal 74Ankit Agarwal 74 

unable to get LastLoginDate

Hi All,
I need One help. 
i m working on community and want to trace the last login date of community user. 
i used query like: 
Select id, Email,  LastLoginDate From User
but the column for LastLoginDate is coming blank...
i need LastLoginDate for further implementation, but i am unnable to populate it.
please help me to resolve it.

thanks
Best Answer chosen by Ankit Agarwal 74
Ankit Agarwal 74Ankit Agarwal 74
i got that, i was doing login from salesforce only due to which history was not creating. now i tried from portal login page and its generated. thank you for your help

All Answers

Raj VakatiRaj Vakati
Try like this 

Select id , Username, Email,LastLoginDate,ContactId, AccountId, IsPortalEnabled from User where IsPortalEnabled = true  

You can update lastlogin like below
 
DateTime lastlogin=System.now();
User u = [SELECT LastLoginDate FROM User WHERE Id =:UserInfo.getUserId()];
lastlogin = u.LastLoginDate;

 
Ankit Agarwal 74Ankit Agarwal 74
hi i used your query but still the lastlogindate column is coming blank, see screenshot. i am using here Admin profile for fetch records. is any special permission required for it.User-added image
Ankit Agarwal 74Ankit Agarwal 74
i got that, i was doing login from salesforce only due to which history was not creating. now i tried from portal login page and its generated. thank you for your help
This was selected as the best answer