0

We currently have set up a process with process builder that creates a task as soon as the opportunity stage is set to no reached.

The due that is basically Today +2 days to get a follow up of the not reached opportunity. The issue we have is that a lot of task are created on the weekends. is it possible to somehow exclude the weekends?

Thanks

New contributor
Belinda is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
0
trigger WeekdayTasks on Task (before insert) {
for ( Task tas : Trigger.new )
{
    if (tas.ActivityDate != null )
    {
        Date origin = Date.newInstance(1900,1,6);
        Date due = tas.ActivityDate;
        Integer x = origin.daysBetween(due);
        Integer day = Math.mod(x,7);           
if ( day == 0 ) // Saturday
{
tas.ActivityDate = (tas.ActivityDate +2);
}
else if ( day == 1 ) // Sunday
{
tas.ActivityDate = (tas.ActivityDate +1);
}
}
}
}

Solved the issue with a process builder creating the task as soon as the opportunity stage is set. The trigger changes the due date if it is on a weekend. The trigger will generally change the date if a task is created on the weekend.

New contributor
Belinda is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
0

For this, we can create a trigger when opportunity creates trigger will fire and we will schedule the batch class in the trigger for 2 days and we will calculate 2 days dynamically for every opportunity record and after two days our batch will create a task on the basis of our logic. Now for weekends, when batch class run it first check the weekday if it weekday it will be scheduled for the next day by batch class.

Not the answer you're looking for? Browse other questions tagged or ask your own question.