Hands on 8 - creating a recurring job using a time-dependent workflow and Process Builder

Until now, we have created a Flow to add new users (user created date greater than or equal to the Flow runtime date) to the Chatter group Sales Executive. To fire the Flow at the same time every day, we have to create a time-dependent action. We will create Workflow Rule and Process Builder on the Schedule Job object; we will use this object to create a scheduler:

  1. First of all, we will create a time-based workflow to update the field On/Off to True. Navigate to Setup (Gear Icon) | Setup | PLATFORM TOOLS | Process Automation | Workflow Rules. Next, click on the New Rule button, and enter the following details:
    • Object: Create a workflow rule on Schedule Job
    • Rule Name: Enter the name Create Schedule Job.
    • Rule Criteria: For the rule criteria, set On/Off to False.
    • Evaluation Criteria: For evaluation criteria, select created, and any time it's edited to subsequently meet criteria.
  2. Once you are done, click on the Save & Next button.
  3. To add a time-dependent action, click on the Add Time Trigger button available under the Time-Dependent Workflow Actions section, and add 24 hours after the scheduled time, as shown in the following screenshot:
  4. Once you are done, click on the Save button.
  5. Now, add a field update action under the time-based trigger to update the On/Off field to True. For this, click on the New Field Update action available under time-based trigger that we defined in the previous steps and enter the following details:
    • Name: Enter the name On/Off to True.
    • Unique Name: This will be auto-populated based on the name.
    • Field to Update: Select On/Off.
    • Re-evaluate Workflow Rules after Field Change: Don't forget to select this checkbox.
    • Checkbox Options: Select the True option.
  1. Once you are done, click on the Save button.
  2. Once you are done with Workflow Rule, activate it by clicking on the Activate button available on Workflow Rule detail page. It should look like what is shown in the following screenshot:
If you want to use Process Builder instead of Workflow Rule, then you have to select Created or Edited in the first step and then tick only when specified changes are made option in the criteria node. This is similar to Evaluate the rule when a record is created, and any time it's edited to subsequently meet criteria in the Workflow Rule.
  1. Now we will create a process to launch the Flow. To create a Process, navigate to Setup (Gear Icon) | Setup | PLATFORM TOOLS | Process Automation | Process Builder, click on the New button, and enter the following details:
    • Name: Enter the name of the Process. Enter Schedule Jobs in Name.
    • API Name: This will be auto-populated based on the name.
    • Description: Write some meaningful text so that other developers or administrators can easily understand why this process has been created.
    • This process starts when: Configure the process to start when a record is created or edited. In this case, select A record changes.
  2. Once you are done, click on the Save button; it will redirect you to the Process canvas that allows you to create the Process.
  3. After Define Process Properties, the next task is to select the object on which you want to create a process and define the evaluation criteria. For this, click on the Add Object node. It will open an additional window on the right-hand side of the process canvas screen, where you have to enter the following details:
    • Object: Start typing and then select the Schedule Job object.
    • Start the process: For Start the process, select when a record is created or edited. This means that Process will fire every time a record gets created or edited.
    • Recursion - Allow process to evaluate a record multiple times in a single transaction?: Select this checkbox only when you want Process to evaluate the same record up to five times in a single transaction. It might re-examine the record because a Process, Workflow Rule, or Flow may have updated the record in the same transaction. In this case, leave this box unchecked.
  1. Once you are done, click on the Save button.
  2. After defining the evaluation criteria, the next step is to add the process criteria. Once the process criteria are true, only then the will Process execute the associated actions. To define the Process criteria, click on the Add Criteria node. It will open an additional window on the right-hand side of the process canvas screen, where you have to enter the following details:
    • Criteria Name: Enter a name for the criteria node. Enter On/Off equals To true as the criteria name.
    • Criteria for Executing Actions: Select the type of criteria you want to define. You can select either Formula evaluates to trueConditions are met (a filter to define the process criteria), or No criteria-just execute the actions. In this case, select Conditions are met. 
    • Set Conditions: This field lets you specify which combination of the filter conditions must be true for the process to execute the associated actions. In this case, set [Scheduled_Job__c].On_Off__c to True.
    • Conditions: In the conditions section, select All of the conditions are met (AND). This field lets you specify which combination of the filter conditions must be true for the process to execute the associated actions.
    • Under Advanced, select No to executing the actions every time.

It will look like what is shown in the following screenshot:

  1. Once you are done, click on the Save button.
  2. Once you are done with the process criteria node, the next step is to add an immediate action to launch a Flow. For this, we will use the Flows action available in Process. Click on the Add Action available under IMMEDIATE ACTIONS; it will open an additional window on the right-hand side of the Process canvas screen, where you have to enter the following details:
    • Action Type: Select the type of action; in this case, select Flows.
    • Action Name: Enter a name for this action. Enter Launch a Flow as the action name.
    • Flow: Select the Flow that you want to execute; in this case, select the Flow Add New Users to Chatter Group.
    • Set Flow Variables: Use this to pass the value in your Flow variables. For the current case, we don't have to pass any value to any variables.
  1. Once you are done, click on the Save button.
  2. The next task is to add the Update Records action available under Process to update the On/Off field to False, so it will trigger the time-dependent workflow and queue a job for the next day. Also, update the scheduled time field with the last modified time of the record; it will queue a job after 24 hours from the record's modified date. Click on Add Action available under IMMEDIATE ACTIONS; it will open an additional window on the right-hand side of the Process canvas screen, where you have to enter the following details:
    • Action Type: Select the type of action; in this case, select Update Records.
    • Action Name: Enter a name for this action. Enter Fields Update as the action name.
    • Record Type: Select Schedule Job record that started your Process. Then, start typing and select the object; in this case, select Schedule_Job__c as the object.
    • Criteria for Updating Records: Optionally, you can specify conditions to filter the records you are updating. Select No criteria—just update the records!.
    • Field: Map the On/Off field to False and Scheduled Time to LastModifiedDate.

It will look like what is shown in the following screenshot:

  1. Once you are done, click on the Save button.

Finally, your process should look like what is shown in the following screenshot:

  1. Once you are done with process creation, the final step is to activate it. To activate a process, click on the Activate button on the button bar.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.66.196