Salesforce Automatic Email Notification and Task Creation by Business Days

How can we send emails with a specific interval of business days and create tasks every time the emails are sent out from Salesforce? In addition, when these tasks reach their due dates

How can we send emails with a specific interval of business days and create tasks every time the emails are sent out from Salesforce? In addition, when these tasks reach their due dates, how can we automatically close and move them to Activity History? Once due date day reaches, open task needs to move to activity history automatically.  The following steps will explain how we can accomplish this business use case in Salesforce.

  • Process Builder to send emails and create tasks.
  • A Scheduler Class to set a flag (which helps to trigger process builder daily if condition meets)
  • A Trigger to capture and update business days elapsed and move open activity to activity history

Let’s discuss the components in details:  

Trigger: 

To capture the business day on the first go, it needs to be checked whether it has value or not. If not then need to populate that field (say Business Date) with needed date and in another date field (say Scheduled Date) next business day calculation needs to be performed based on the date that populated initially on the ‘Business Date’ field.

For example,

If Business Date – 27th March 2017, then Scheduled date will be 3rd April 2017 (5 business Day)

One part of trigger is completed and another part will be moving to activity history automatically. Let’s discuss this part later.

Process Builder: 

Below are 2 different conditions to trigger Process builder based on Account name which will send separate email template based on condition.

For example,

If Status – In Progress and Trigger Date (Date Field) <= Today () and (Account Name = ‘XXX’ or Account Name = ‘YYY’) ———– Email Template specific for Trigger Date needs to be sent along with task/activity creation

If Status – In Progress and Trigger Date (Date Field) > Today () and (Account Name = ‘XXX’ or Account Name = ‘YYY’) ———– Email Template specific for Trigger Date needs to be sent along with task/activity creation

Along with the above condition, it is necessary to include flag field (say isTrigger – checkbox) which should be unchecked.

Once above condition is met, we need to create open task with due date as ‘Scheduled Date’ (which is mentioned in trigger part above) in immediate actions. Open task will create with due date as 3rd April 2017.

In scheduled actions in process builder, we need to set “‘0’ days after Scheduled Date” which will set time as after 5 business day. Then, we need to create above specified items as below. These items will execute on 3rd April 2017 as per above example given.

  1. Send Email
  2. Open Task with due date as ‘Scheduled Date’
  3. Update ‘Business Date’ as ‘Scheduled Date’
  4. Update ‘isTrigger’ flag to ‘True’

It is necessary to update business date as scheduled date (Point 3) as it helps to update scheduled date to next 5 business day recursively if specified conditions are met. And updating the flag to true helps to trigger the process builder.

Scheduler Class: 

Scheduler class helps to update the flag ‘isTrigger’ to false, so that it will trigger process builder. This class needs to be run on daily basis (morning), and it helps check whether the condition to send email and task creation is met or not daily.

So on 3rd April 2017, ‘isTrigger’ will be set to ‘True’ and this scheduler class will update it to ‘False’ which will trigger process builder and next schedule date will assigned until status remains in ‘In Progress’.

Now all the specified tasks are completed except moving the open task to activity history if due date of task equals today. Since everything is happening under account, there is no possibility to check the task’s due date with Today (). So we can use the ‘Business Date’ in account to Today () (as business date is populated to scheduled date in process builder above)

In Trigger, we need to capture these conditions in order to move the open task to activity history. This is another part of trigger’s play in this scenario.

Below is the pictorial representation of above scenario.

send notification email salesforce
send notification email salesforce

Reference Link:  

https://help.salesforce.com/articleView?id=process_overview.htm&type=0

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_scheduler.htm

About MST

At MST Solutions our cornerstone is to adapt, engage and create solutions which guarantee the success of our clients. The talent of our team and experiences in varied business verticals gives us an advantage over other competitors.

Recent Articles

Work with us.

Our people aren’t just employees, they are key to the success of our business. We recognize the strengths of each individual and allow them time and resources to further develop those skills, crafting a culture of leaders who are passionate about where they are going within our organization.