Lack of adoption is a common issue in almost all companies using Salesforce. A lot of strategies are usually woven to tackle this issue. Some of them includes setting up Dashboards(like a Wall of Shame), Gamification etc. Now, another way to tackle this would be to record how much time each Sales Rep or a Salesforce User spent his or her time in Salesforce. This can actually be recorded by looking at the Login Time and the Logout Time. And then you can perceive how well each of your team members are doing well within Salesforce. So join me on this blog post wherein I will explain how you can capture the Login/Logout time within Salesforce for each of your Users and help to improve adoption.
There are basically two solutions to this trivial problem. I will be explaining the first one in this blog post that involves Login Flows. The other solution using the Event Monitoring API will be discussed in detail in my next blog post.
Firstly, I create a custom object to store the Login values and Logout values. Lets name the object as ‘Login Hours’. It will have two Date/Time fields to store the Login time and Logout time. I named them as ‘Login Time’ and ‘Logout Time’ in my case. It will also have two formula fields. One field is to calculate the time spent on Salesforce. And the other is to calculate just the Date value from the Login Date field. This is required to keep track of time if the user logs in more than once on the same day. I also have Number field ‘Time Spent’ to keep the sum of time spent in Salesforce on a particular day.
Then I create two Flows to collect the Login time and the Logout time.
The first Flow will be to calculate the Login time. The Flow fetches the Login Hour Record of the current user with the current date. It then checks if the User has logged in today with the help of the ‘Login Date’ field and if there are no Login Hours record for today then it creates one and stores the current time in the ‘Login Time’ field and if there is already a Login Hour record with the current date, then it updates the ‘Login Time’ field with the current time.
The second Flow is created to calculate the Logout time of the User. The Flow fetches the ‘Login Hours’ record with respect to today’s date. It then checks if the login was made today, and it then updates the ‘Logout Time’ field with the current time. It then again does a record update and updates the ‘Time Spent’ field.
Setting up Login Flows
The Flow to store the Login Time should run at the time of login. For achieving this, we have an amazing feature in Salesforce which the Winter ’15 release awarded us – The Login Flows. Login Flows help us to run a Flow at the time of login. It is useful when we want to do some authentications, collect or update data at the time of login etc. Hence I go to the ‘Login Flows’ section in Salesforce and select my first Flow. And thus the Flow would run at the time of Login and would store the ‘Login Time’ field in the Login Hours object.
The markup for embedding the Logout Flow within a VF page is as shown below.
Now you might be wondering why we embedded the second Logout Flow within a VF page.
Scroll down to know why ! 😉
And I want this script to run on the start itself. So I install an extension called TamperMonkey which helps me to run my scripts whenever my Org is opened.
You can install the script straight into your TamperMonkey Extension.
Here is the link for it – https://greasyfork.org/en/scripts/25016-custom-logout-flow-for-salesforce
Don’t panic if you think this is too much for you or if you are lazy to do all this. I have created an unmanaged package which you can install in your Org to achieve this – https://login.salesforce.com/packaging/installPackage.apexp?p0=04t28000000TdMF
Once you install this package, all you will have to do is, install the TamperMonkey script via GreasyFork and setup the Login flow. 🙂
Would you like to watch how it works? If so, check out this video.