You need to sign in to do that
Don't have an account?
Sylvie Serplet
How to exclude weekend on recurring task due date?
I have created recurring tasks such as 'Occurs on day 10 of every 1 month'. The problem is when they fall on a week end. I could not figure it out how to make the task falls on the Friday preceding the week end if it falls on a Saturday or a Sunday. All tasks are already entered in the Salesforce.
Any Idea?
Thank you.
Any Idea?
Thank you.
I have to change the trigger for 'after insert' to 'before insert' to make it works. There is the code and the test class (81% coverage).
All Answers
we dont have any option as such in our standard reccurence functionality for Task to exclude week-ends on selction of option "daily" but we can change them at the time creation using trigger.
you can refer this example and build the logic as per your requirement.
trigger CreateFlowupTask on Account (after insert){
List<Task> tasks = new List<Task>();
List<Account> Acc = Trigger.new;
for (Account Accs : Acc ) {
date shipDate = Accs.ship_date__c;
//add 2 days because your followup task is shipdate plus 2 days
date followUpDate= shipDate.addDays(2);
date checkDate = date.newInstance(1900,1,7);
//count days between 2 days
integer numberDaysInBetween = checkDate.daysBetween(followUpDate);
//modulus calculation in apex
integer sum = math.mod(numberDaysInBetween,7);
date finalFollowUpDate;
//compare and if match found than add days acconding to it
// 0 = sunday , 1 = monday, 2 = tuesday, ......, 6 = saturday
// so if followup day is saturday than add 4 days from your shipdate
// if followup day is sunday than add 3 days from your shipdate
if(sum == 6){ finalFollowUpDate = shipDate.addDays(4); }
else if (sum == 0) { finalFollowUpDate = shipDate.addDays(3); }
else { finalFollowUpDate= shipDate.addDays(2); }
// task creation in trigger
Task tsk = new Task(whatID = Accs.ID, Ownerid = Accs.OwnerId, Subject = '2nd Day follow-up Call', ActivityDate = finalFollowUpDate);
tasks.add(tsk);
}
insert tasks;
}
let me know, if it helps you or need any help :)
shiva.sfdc.backup@gmail.com
Thank you for your response.
I am using the Task on Case and not on Account and I do not have an extra date such as shipDate to make the calculation. It is the recurring Due date that need to be changed.
I have come accross the following trigger on a forum but it does not look to update the task already entered in Salesforce.
Any other thought?
I have to change the trigger for 'after insert' to 'before insert' to make it works. There is the code and the test class (81% coverage).
I could not get time to look into that. good catch that you found the cause your self :)
shiva.sfdc.backup@gmail.com