You need to sign in to do that
Don't have an account?
adroitus
Public Holiday Formula needed for leave application
Hello Developer.
- i want to know how to exclude public holiday from business day if someone apply for a leave. Done with weekend days exclusion.
i need u r help....
Thanks & Regards
Ashish Agrawal
Create Holidays. Admin Setup --> Comapany Info --> Holidays
Once you have configured the holidays, Write an Apex trigger (before insert) for the Custom object to check for holidays and add the other business logic to exclude that day, whenever a new leave application is submitted.
All Answers
Create Holidays. Admin Setup --> Comapany Info --> Holidays
Once you have configured the holidays, Write an Apex trigger (before insert) for the Custom object to check for holidays and add the other business logic to exclude that day, whenever a new leave application is submitted.
Hello,
Thanks for u r Hint....
PLz help me...
Are you using a custom object to manage leave applications ?
Can you please provide the details of your use case...
Hello,
Yes i am using custom objects for leave apllications.
details:
managed_Appsamp__Start_Date__c(for start date)
managed_Appsamp__End_date__c(for end date)
managed_Appsamp__leave_days__c(number of days will stored in this field)
need a sample code /formula for this .
ok.
Let me verify that I understand your use case correctly...
Based on the leave start date and end date, you first check for weekends, then holidays and finally, the number of days is calculated and stored in the managed_Appsamp__leave_days__c field.
YES ,well understood my need....
something quick : this will work if the year is same... for instance if you have start date as dec 20, 2011 and end date as Jan10, 2012... you will have to add some business logic for that........
trigger trgLeaveAppBeforeInsert on <Custom Object name>(before insert) {
Date startDate, endDate;
Integer startDayofYear, endDayofYear, totalDaysFinal,totalDaysInitial;
if(trigger.isInsert){
for(<Custom Object> obj : Trigger.new){
startDate = obj.managed_Appsamp__Start_Date__c;
endDate = obj.managed_Appsamp__End_date__c;
if(startDate.year() == endDate.year()){
totalDaysInitial = endDate.dayOfYear() - startDate.dayOfYear();
totalDaysFinal = totalDaysInitial;
for(integer i = 0; i< totalDays; i++){
for (Holiday hObj : [Select activityDate from Holiday]){
if(startDate.addDays(i) == activityDate){
totalDaysFinal--;
}
}
}
}
obj.managed_Appsamp__leave_days__c = totalDaysFinal;
}
}
}
hello !!!
Error!!!
Error: Compile Error: Variable does not exist: activityDate at line 22 column 52
sorry.. it should be
if(startDate.addDays(i) == hObj.activityDate){
Thanks a lot APAI i have done with it and its working fine..
Thank u Once Again for u r gr8 Support
Thanks & Regards
Ashish Agrawal
Salesforce CRM
Good to know that it works ! :-)
A
Thanks in advance
requirement