You need to sign in to do that
Don't have an account?
Madhu navuluri 4
How to calculate number of hours entered by a user in a single day
Hi Team,
I have an object called Leave Tracker, where users enter the leave date, reason, and number of hours, user can create more than one record in a day with different hours, ex: 1 entry with 2 hours and another entry with 4 hours. but my request is that we should not allow a user to create/update a leave tracker record if the leave hours are more than 8 in a single day per user?
any help is appreciated.
Thanks,
Madhu
I have an object called Leave Tracker, where users enter the leave date, reason, and number of hours, user can create more than one record in a day with different hours, ex: 1 entry with 2 hours and another entry with 4 hours. but my request is that we should not allow a user to create/update a leave tracker record if the leave hours are more than 8 in a single day per user?
any help is appreciated.
Thanks,
Madhu
Try Below Code Please Mark It As Best Answer If It Helps
Thank You!
Thanks for taking the time and share the information. here the request is that user can create more than one leave request in a single day, so i have to get all leave records and count the hours in each leaves record before the user create a new or update an existing and collectively "number of hours in a single day per a user shouldn't be more than 8.
Thanks,
Madhu
Hi Madhu navuluri 4
Thanks
Suraj Tripathi
Can you please share the any relation ship between objects ,
Solution Approach:
- because Employee(Parent) and LeaveTracker(Child) then we can calculate exact that's you need.
- if employee try to enter leave then first we need to check existing leave applied for this date, if this employee already applied 8 hours leave then we can display error message and employee not applied 8 hrs leae for this date then we allow for
- for this approach we need SOQL on this Parent and Child
if you need any assistanse, Please let me know!!Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Leave tracker is related to the user object.
User Madhu created a leave record with 2 hours on date 23-May-2021, user Madhu should be able to create another record with 3 hours on 23-May-2021, if user Madhu creates a third record with 3 hours of leave on 23-may-2021, then the system should allow user, because all 3 records collectively less than or equal to 8 hours, in this case, user Madhu tries to create 4th record on 23-may-2021 then system through error.
Thanks,
Madhu
Try Below Code Please Mark It As Best Answer If it Helps
Thank You!
Please use my concept As i mentioned earlier.
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
The calculation of leave hours in a single day rely on getting all the Leave Tracker records for the User on a given date.
I would update the Query so that it uses the "Date of Leave" field on the triggered record, not CreatedDate = TODAY()
The challenge becomes if the trigger is for multiple records with multiple dates and/or users.
regards
Andrew