Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Please note that I don't want to know the interval between logins - I want to know how many minutes (or hours) elapsed between a login and the subsequent logout. Is it possible to calculate this in SFDC, using any combination of technologies?

share|improve this question
    
lastlogintime - timenow will be the formula right? by querying the loginhistory, I found the latestlogin and subtracted it from the current time and got the number of hours the user is logged in ? won't that help? –  rao Dec 20 '12 at 19:09
    
@rao that wouldn't work because you need the logout time too, right? –  Ryan Guest Dec 20 '12 at 19:57
    
@RyanGuest ah i thought the question was to see how long the user was logged in :/ –  rao Dec 20 '12 at 21:28
add comment

2 Answers

The logout times are not recorded so unless you wrote a browser extension or tied a JavaScript event to the click of the logout button , im afraid it isn't possible to retrospectively calculate the logged in duration of the user.

You could have a sort of 'heartbeat' embedded in the sidebar running as a JavaScript polled job I suppose which kept writing / updating a user specific record in a custom object ever so often while a user was logged in. Every time a user logged out there would be a significant pause in the writing of these 'active' records .

share|improve this answer
    
That's very interesting. Could you point me to an example? I'm having a bit of trouble visualizing a "heartbeat". –  John Westenhaver Dec 24 '12 at 20:00
add comment

Open your debug log and paste this :

You can create a page use this as a controller and display the difference to the user(or) use it apex code as a method:

List<Loginhistory> login = [SELECT UserId, LoginTime from LoginHistory where userid=: userinfo.getuserid() and logintime = today order by logintime asc];
    decimal  numberofhours;
    decimal numberofmiuntes;
    integer size = login.size();
    numberofhours = ( system.now().hour() - login[size-1].LoginTime.hour()  );
    numberofmiuntes = (system.now().gettime() - login[size-1].LoginTime.gettime())/60000;  
    system.debug('Hours: '+numberofhours + ' Minutes:'+ numberofmiuntes);
share|improve this answer
    
This is the number of hours and minutes the current user has been logged in, while this user is still logged in. After this user logs out, I'd like to know how long the user WAS logged in. The heartbeat idea above is very interesting but I'm not sure how to build it in a way that doesn't eat up too much bandwidth ... –  John Westenhaver Dec 24 '12 at 20:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.