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
Praveen BonaluPraveen Bonalu 

how to capture time on visualforce in salesforce

Here is my requirement

1)In a day we have 2 sessions.In the morning session once click on[clock IN Button] Time starts counting.

2)In the lunch time if i click on [click Pause button] it should stop recording the time.

3)On a Click of log out at evening[click logout button] . On the same click of logout button insert the record taking difference of duration and also use user info to identify the User in a custom object

So that we can calculate the Employees productive hours of working.

How can i Achieve this Functionality in salesforce

Please Share the Ideas.
Daniel BallingerDaniel Ballinger
You could create a custom object with a Master Detail relationship to User. Then add four custom DateTime fields to capture the respective start/stop times. Probably only the first start datetime would be required.

You can create or update this record based on the current date and the active users User Id.

You could take this a step further and add formula fields to easily find the hours worked for that day.
Praveen BonaluPraveen Bonalu
Hi Daniel ,

Thanks for your reply 

I have created a session object (Master-detail-relationship) with user object.

I have created the following fields on the object :

User Name (master-detail relationship)
login time (Date/Time Field)
Logout Time (Date/Time Field)
Total Hours ( Formula "which will take the values from the two date fileds and calculate the hours )

How would i insert a  record in to "session" object  automatically when the user log in to the salesforce instance (Login Time) and as well as the logout time needs to be populated when the user logs out.

can you please provide me some example /logic 

Thanks
Praveen 
 
Daniel BallingerDaniel Ballinger
You want this process to be fully automated now?

I thought the original intention was they would press a button to login/logout. If that was the case a simple Visualforce page would work.

You might be better off using the Event Monitoring API (https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/using_resources_event_log_files.htm). There are Login and Logout events that you can monitor to get the data (as long as users explicitly logout of Salesforce)

See also: Execute an action / run a trigger every time a User logs in to Salesforce
Praveen BonaluPraveen Bonalu
I am sorry Daniel,

I have mis lead you I guess.I need to create a visualforce page with a colck having (Buttons:Start,Stop,Pause).when the user click start ,the start time login time (Date/Time Field) needs to be recorded and when the usr clicks stop the stop time needs to be inserted (
Logout Time (Date/Time Field)

They should be inserted a record in the custom object called session.

Thanks
Praveen 


 
Daniel BallingerDaniel Ballinger
This should be straightforward to achieve. On your Visualforce page you can use apex:commandButton elements to call apex methods in the backing controller class. The apex methods can use the current UserInfo and DateTime to insert or create the custom session objects as required.
Bhaswanthnaga vivek vutukuriBhaswanthnaga vivek vutukuri

I feel like it should be done with counter and saving the time in text field.

or you can completely do it JS and save that value to the text field in salesforce,  using ajax api.