,

Workflows

On the Force Platform platform, workflows are associated with particular Force Platform objects. The diagram below presents the anatomy of a workflow.

Figure 64. Steps in a workflow


Workflow processing is triggered by a user saving a record with a workflow action assigned to it. The Force Platform workflow engine evaluates whether this particular data change should trigger the workflow action. If the save action is appropriate, the workflow engine checks to make sure that this particular record meets the criteria described for the workflow rule. If the record meets the criteria established for the workflow, one or more actions are performed.

There are four types of workflow actions available:

  • Task - an action assigned to a user or a role. Every task has a subject, a due date, which can be a specific date or a relative date, a status and a priority. You can also include comments on the task record.

  • Email alert - sends an email message, based on a template, to a specified email address. The email can include data from the record spawning the email.

  • Field update - updates another field on a Force Platform record. Field updates are part of the same transaction as the Save action spawning them.

  • Outbound message - sends data to an external endpoint. Outbound messages are handled by a separate Force Platform service. If delivery of an outbound message fails, the service continues to retry the delivery for 24 hours. Outbound messaging is a powerful feature used to coordinate data updates of Force Platform data with external data stores.

As with the other Force Platform capabilities you have seen in this book, the best way to learn about workflows is to create some.

A Simple Workflow for Alerts

The first basic workflow you create familiarizes you with the process. This workflow sends an email message to the hiring manager for a position whenever anyone applies for that position.

1.
Begin the definition of a workflow by clicking Setup Create Workflow & Approvals Workflow Rules. Click Continue to proceed beyond the introductory page, and then click New Rule to begin the definition process.

2.
Select the Position object and click Next, which will bring up the page shown, in its completed form, in the figure below.

You want to have an email alert sent whenever a new Job Application comes in, so why are you entering the workflow rule on the Position object? The reason you want to use the Position object is so you can direct the email to the Hiring Manager, who is identified on a field in the Position record.

Remember, the Number of Applicants field is a Rollup Summary Field on the Positions record, and this field is updated each time a Job Application record is added or deleted for a position. These changes can trigger a workflow on the Position record.

Figure 65. Defining a workflow


3.
Enter Application Notification for the Rule Name, and give the rule a description of Notifies the Hiring Manager when an application comes in for one of their positions.

4.
Set the Evaluation Criteria to Every time a record is created or edited.

You can set the Rule Criteria to limit when a workflow is fired. Remember that the Number of Applications Rollup Summary Field is updated every time a Job Application record is added or deleted. You do not want to send an email alert when a Job Application is deleted, so you can use the formula option to specify a Rule Criteria to handle this scenario.

5.
Change the Rule Criteria to formula evaluates to true. Enter the following formula into the text area by clicking Insert Field, Insert Operator, Insert Selected Function and then highlighting the argument for the PRIORVALUE() function and Insert Field again to produce the following code:

Number_of_Applications__c >
PRIORVALUE(Number_of_Applications__c)

This function checks to make sure the Rollup Summary Field is incrementing, indicating a new application, rather than decrementing from an application being deleted. The formula also prevents the workflow from being triggered by changes to any other field in the Position record.

6.
Click Save and Next to save the workflow rule and bring up the page shown below.

You have defined a workflow rule, indicated when the rule is evaluated, and specified criteria that limit when the workflow actions associated with the rule are taken.

Your next task is to define the workflow actions to be taken when the workflow is triggered.

Figure 66. A workflow defined


7.
Click New Email to bring up the email alert definition page shown in the following figure.

The list of available workflow actions includes creation of a new task, email, field update or outbound message, and the option to assign an existing action to the workflow.

Voice of the Developer

Workflow actions exists separately from use in any workflow, so you can execute the same action from multiple workflows. This reuse can help to standardize your actions as well as reduce ongoing maintenance overhead, should you want to change a particular action that is used in more than one workflow.

Figure 67. Defining an email alert for a workflow


8.
Give the new alert a description of Notifies Hiring Manager of job application.

9.
Select an email template of Application Notification. This email template was loaded into your organization at the start of this chapter. The email includes data from the Position record.

10.
Select Related User for the Recipient Type, causing Hiring Manager and Last Modified By options to appear in the Available Recipients picklist. Add the Hiring Manager to the Selected Recipients picklist.

You have quite a bit of flexibility in terms of the recipient of this email alert. You can specify that the email goes to the owner of the record, the people in a particular role or public group (security designations you will learn about in Chapter 7: Protecting Your Data), or an email field on the record. You can choose multiple email addresses from as many of these categories as you like, or even include up to five specific email addresses entered in the text box at the bottom of the page.

11.
Click Save to return to the Workflow Actions page. Click Done to go to the detail page for the workflow rule, which contains a summary of the workflow.

12.
Click Activate to activate this workflow.

Forgetting to click Activate is one of the most common errors in creating and using workflows. The ability to activate and de-activate workflows allows you to turn off a workflow if you do not need or want the workflow actions to execute, such as when you are doing a bulk data load.

Note

There may be some bulk actions which will not cause workflow rules to be fired. Check the online documentation for the latest list of these exception cases.

The workflow is now in operation.

13.
Click the Positions tab and select a position. Add a new Job Application for a position.

14.
Check the email assigned to the owner of the Position record to see the results of the workflow rule.

Implementing this type of automatic notification is pretty easy on the Force Platform platform. But your initial pass at this functionality may not be appropriate for all position owners. In the next section, you modify the new workflow to adapt to the preferences of your user community.

Modifying the Simple Workflow

The good news is that the Hiring Manager for a position now gets an email every time someone applies for one of their open positions. The bad news is that some of these owners actually don’t want to be bothered every single time one person applies for what may be a very popular position.

You can accommodate these owners with a simple change to the Position record, coupled with a modification of the Evaluation Conditions for the workflow.

1.
Return to the Position object by clicking Setup Create Objects and then the Edit link on the Position object.

2.
Add a new Checkbox field. Give the field a Field Label of Notify Hiring Manager of application, a default value of Checked and a Field Name of Notification, rather than the default field name as usual, as well as an appropriate description and help text.

3.
On the next page, accept the default security and click Save, accept the default layout option on the next page and click Save.

Finally, modify the formula, taking this new option into account. Why modify the formula? For a workflow, you can have either multiple criteria or a single formula. As you will see, though, you can create a formula that checks for multiple criteria.

4.
Go to edit the workflow you just created by clicking Workflows & Approvals Workflow Rules and the Edit link for the workflow rule. Modify the formula to the following code:

( Number_of_Applications__c >
PRIORVALUE(Number_of_Applications__c)
    && Notification__c

The && is used to link together required conditions, similar to using AND in other languages.

5.
Click Save to save your changes.

6.
Go to the Positions tab and select a Position.

7.
Check the notifications checkbox and add a new application. Check the email for the Hiring Manager.

8.
Uncheck the notifications checkbox and add a new application. Check the email to make sure that no notification is sent.

9.
Recheck the notifications checkbox and delete an application. Check the email to make sure no notification is sent.

The changes you made in your Force Platform object and your workflow provide an example of one of the great virtues of the Force Platform environment. Since changes you make to your applications can be instantly available to your users, you can make these two small modifications in near real time. This velocity has the effect of allowing you to make development a truly interactive and iterative process, involving users to get their signoff as you shape and hone their applications.

..................Content has been hidden....................

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