trailhead

Learning Objectives

After completing this unit, you'll be able to:
  • Describe what types of business processes you should use a workflow rule for.
  • Define a workflow rule and what it’s comprised of.
  • Set up a workflow rule that escalates a case and assigns a follow-up task.
  • Set up a workflow rule that updates a field on a record at a particular time.

Workflow

Workflow lets you automate standard internal procedures and processes to save time across your org. A workflow rule is the main container for a set of workflow instructions. These instructions can always be summed up in an if/then statement. For example:

If it’s raining, then bring an umbrella.

Tip

Tip

Whenever possible, automate your if/then statements with Process Builder instead of workflow rules.

Workflow rules can be broken into two main components.
  1. Criteria: the “if” part of the “if/then” statement. In other words, what must be true of the record for the workflow rule to execute the associated actions.
  2. Actions: the “then” part of the “if/then” statement. In other words, what to do when the record meets the criteria.

In the raining example, the criteria is “it’s raining” and the action is “bring an umbrella”. If the criteria isn’t met (it isn’t raining), then the action isn’t executed (you don’t bring an umbrella).

Criteria: Narrowing Down the Scope of a Workflow Rule

In a workflow rule, the criteria narrows down the pool of possible records that the actions might be executed for. To set the criteria for a workflow rule, you configure:
  • The object that determines the records the workflow rule cares about. This object determines the records the workflow evaluates, as well as the fields available for setting the rule criteria.
  • Evaluation criteria that determine which changes trigger the workflow rule—such as only when accounts are created.
  • Rule criteria that identify what must be true about the record for Salesforce to execute the associated actions. Any change that causes a record to match this criteria can trigger the workflow rule—even changes to hidden fields.
Example: If an account is created or updated and it’s located in Texas, you want Salesforce to automatically perform certain actions. Here’s how that if-statement breaks down into workflow rule criteria.
  • An account (object)
  • is created or updated (evaluation criteria) and
  • is located in Texas (rule criteria)

Actions: What to Do When Criteria Are Met

When a record meets all the criteria for a workflow rule, that rule’s actions are executed.

First, figure out when to execute the action. You have two options.
  • Immediate actions, like their name suggests, are executed as soon as the workflow rule finishes evaluating the record. Example: when a new high-value opportunity is created, email the opportunity team.
  • Time-dependent actions are executed at a specific time, such as 10 days before a record’s close date. When that specific time passes, the workflow rule re-evaluates the record to make sure that it still meets the rule criteria. If the record does, the workflow rule executes those actions.
    Note

    Note

    If you selected “created or edited” for your evaluation criteria, you can’t add time-dependent actions. You can monitor and cancel pending time-dependent actions from Time-Based Workflow in Setup.

Before you can add a time-dependent action to a workflow rule, you first have to identify when those scheduled actions should be executed. Enter the time trigger. When you create a time trigger, you identify a time at which you want Salesforce to execute certain actions. To do so, you select a date or date/time field and specify an amount of time before or after that field. For example, the following time trigger starts a month before an account’s service contract expires.
Screenshot of an example time trigger

The equivalent to “now” in a workflow time trigger is “Rule Trigger Date”. For example, if you want to send an email a week after the workflow rule evaluates this record, select 7 Days After Rule Trigger Date.

As far as what the action does, here are the different actions that you can add to a workflow rule. Each of these actions is available as both immediate and time-dependent actions.
  • Email Alert—Send an email by referencing an email template. For example, email sales management when a sales representative qualifies a large deal.
  • Task—Create a task. For example, assign follow-up tasks to a support representative.
  • Field Update—Update a field on the record that the workflow rule evaluated or a related record. For example, when a user record is created, set the Active field to true.
  • Outbound Message—Send a secure, configurable API message (in XML format) to a designated listener. For example, send a message to an external HR system to initiate the reimbursement process for an approved expense report.
Example: If the criteria are met, update the account owner and assign the account owner a task three days later to call the account’s contact. Here’s how that “then” statement translates into workflow actions.
  • update the account owner (immediate action—field update) and
  • three days later (time trigger), assign the account owner a task to call the account contact (time-dependent action—task)

Defining Workflow Rules

Tip

Tip

Draw out your business process before you try to automate it. Doing so will make it much easier to configure when using one of our tools for process automation.

  1. From Setup, enter Workflow Rules in the Quick Find box, then select Workflow Rules.
  2. Click New Rule.
  3. For Object, select Account.
    Every workflow rule is directly associated with one and only one object. The object is the first thing that narrows the scope of a workflow rule, in that it tells the rule that it only needs to pay attention to these kinds of records. For this example, we’re telling the workflow rule to look at only accounts.
  4. Click Next.
  5. Name the workflow rule Texas Accounts. While you’re at it, give it a description, too.
  6. In the Evaluation Criteria section, select created, and any time it’s edited to subsequently meet criteria.
    The evaluation criteria let you identify which changes you want the rule to evaluate.
    Option Description What it means for this use case
    created Evaluate the rule criteria each time a record is created. If the rule criteria is met, run the rule. Ignore all updates to existing records. With this option, the rule never runs more than once per record. The workflow rule doesn’t handle accounts that move to Texas after their account record is initially created.
    created, and every time it’s edited Evaluate the rule criteria each time a record is created or updated. If the rule criteria is met, run the rule. With this option, the rule runs every single time a record is edited, and it executes immediate actions as long as the record meets the rule criteria. The workflow rule runs every time an account that’s located in Texas is updated, not just when an account is updated to be located in Texas. The workflow would run for irrelevant changes, such as the description being updated. That means that it would run for both of these cases.
    • The account is already located in Texas, and its description is updated.
    • The account is located in California, and its location is updated to Texas
    created, and every time it’s edited to subsequently meet criteria (Default) Evaluate the rule criteria each time a record is created or updated.
    • For a new record, run the rule if the rule criteria is met.
    • For an updated record, run the rule only if the record is changed from not meeting the rule criteria to meeting the rule criteria.

    With this option, the rule can run multiple times per record, but it won’t run when the record edits are unrelated to the rule criteria.

    The workflow runs when an account:
    • is created and is located in Texas
    • is edited to be located in Texas (i.e. its location before being edited isn’t Texas and its location after being edited is in Texas)
  7. In the Rule Criteria section:
    1. Set Field to Account: Billing State/Province.
    2. Set Operator to equals.
    3. Set Value to TX.
      This rule criterion ensures that the workflow rule will execute its accounts only for accounts whose Billing State has been updated to Texas.
      Screenshot of workflow rule criteria that checks if the account's billing state field equals TX
  8. Click Save & Next.

Once you create the workflow rule and identify the evaluation and rule criteria—so the workflow rule knows when it should act on a specific record—add actions to that workflow rule. For this use case, add one immediate action and one time-dependent action. Of course that means you’ll also create one time trigger.

Add a Time Trigger to the Workflow Rule

  1. Click Edit.
  2. In the Time-Dependent Workflow Actions section, click Add Time Trigger.
  3. Configure the time trigger to be 1 Day After Rule Trigger Date.
    For this time trigger, Salesforce will execute the associated time-dependent actions one day after the rule evaluates the record.
    Screenshot of time trigger
  4. Click Save.

Add Actions to the Workflow Rule

Now that you’ve set up the time trigger, add the actions. Just a reminder: for this use case we need to update one field immediately and assign one task under the time trigger.

  1. Add an immediate Field Update action.
    1. Under Immediate Actions, click Add Workflow Action | New Field Update.
    2. Name the field update Texas Owner, and give it a description.
    3. Select the Account Owner field
    4. Click Lookup, and select a user.
      Since you’re using a Developer Edition, you may not have many users to choose from. This is just a test, so pick whatever’s available—even yourself!
    5. Click Save.
  2. Add a Task action under the time trigger that you created.
    1. Under 1 Day After Rule Trigger Date, click Add Workflow Action | New Task.
    2. Assign it to the user that you selected for the Account Owner field.
    3. For Subject, enter Follow Up with New Account.
    4. Make the task due 3 days after the rule was triggered.
    5. Click Save.
  3. Click Done.

Activate the Workflow Rule

You’re almost there, but not quite done yet! Workflow rules don’t actually start evaluating changes to records until you’ve activated the workflow rule.
  1. On the workflow rule detail page, click Activate.
    You get a message that says “The Default Workflow User must be set before activating this workflow rule.” If Salesforce tries to execute time-dependent actions and the user who originally triggered the associated workflow rule isn’t active, Salesforce uses the default workflow user.
  2. Click OK.
    Salesforce redirects you to the Process Automation Settings page.
  3. In the Default Workflow User field, enter your name.
    We recommend using a system administrator as your org’s default workflow user.
  4. Click Save.
    Salesforce redirects you to your (now active) workflow rule.
Your rule looks something like this.
Screenshot of final workflow rule

Tell Me More...

You can create as many Field Update, Task, Email Alert, and Outbound Messages actions as you want. Once you create a workflow action, you can use that action across multiple workflow rules. To use an existing action on a workflow rule:
  1. From Setup, enter Workflow Rules in the Quick Find box, then select Workflow Rules.
  2. Select the workflow rule that you want to add the action to.
  3. Click Edit.
  4. Click Add Workflow Action | Select Existing Action.
  5. Select the type of action that you want to add.
  6. Move the appropriate actions from Available Actions to Selected Actions by selecting them and clicking the left arrow.
  7. Click Save.
  8. Click Done.

Resources

Lightning bolt icon used to indicate that the content is for Lightning Experience

Remember, this module is meant for Lightning Experience. When you launch your hands-on org, switch to Lightning Experience to complete this challenge.

Time Estimate
Topics
retargeting