How To Write A Salesforce Workflow Rule


One of’s most useful features is the ability to automate business processes via workflow rules. Using workflow rules, you can define specific actions that will take place whenever records are saved and meet certain criteria. For example, you could set up an action to automatically send an email to your Director of Sales whenever an Opportunity is updated so that the Stage equals “Closed/Won,” or you could set a task for a user to call a Lead whenever a new Lead record is created. While it is, for the most part, fairly simple to set up a workflow rule, it can at times be tricky. Hopefully this article will help you get up to speed on some of the basics.

The Big Picture

At a high level, there are three steps that you need to complete in order to set up a workflow rule: select the object upon which the rule will operate, define the criteria that specify when the rule should run, and define the actions to take when the an updated record satisfies the criteria. Ready to get started? Go ahead and navigate to Setup | Create | Workflow & Approvals | Workflow Rules and then click on the New Rule button.

Select an Object

The first step is to select the object to which the new rule applies. Just select the correct object from the dropdown menu and then click Next.

Define the Criteria

First, name the rule and write a brief, easy-to-understand description of the rule’s purpose. Next chose the Evaluation Criteria; this determines when Salesforce will decide to evaluate the rule criteria. You can choose whenever a record is created, whenever a record is created or edited, or whenever a record is created or edited to subsequently meet criteria (in other words, if it already satisfied the criteria before it was edited, the rule won’t run). Which option you choose depends on your specific scenario.

Now, on to the fun part, where you’ll write the logic that determines whether or not the rule should fire for a particular record. You have two options, which you can select from the dropdown menu: run the rule if the following criteria are met or run the rule if the following formula evaluates to true. With the first option, you can compare fields to static values that you specify based on simple operators like equals, not equal to, starts with, or contains. With the second option, you can create more complex criteria, by writing a boolean expression (that is, one that evaluations to true or false).

Salesforce provides you with a large set of functions that you can use in your workflow formula. You can view a complete list of them by heading over to the Salesforce help docs, but I’ll go over a few of them here:

ISPICKVAL(picklist_field, text) — If you need to compare the value of a picklist field with a text literal in your formula, you need to use this function. For example, if you have a picklist called Picklist__c and it’s value is “Value 1” on the record you are checking, then ISPICKVAL(Picklist__c, “Value 1”) will return TRUE.
AND(logical_test_1, logical_test_2, …) — If you have more than one test, and all must evaluate to true, then you would use this rule. For example, if you only want your rule to fire on records with Picklist__c equal to “Value 1” and Company = “Company A”, then you would write AND(ISPICKVAL(Picklist__c, “Value 1”), Company = “Company A”)
ISBLANK(expression) — This function will return true if the input expression is blank. 
Also, note that you can nest functions, as I did in that second bullet point. There are a ton more functions at your disposal when writing workflow rules, so it is definitely worth checking out the Salesforce documentation to get a better grip on them.

Define the Actions

Once you are satisfied with your rule criteria, click Save & Next, and you will be taken to a screen where you can add action to your workflow rule. Click on the Add Workflow Action dropdown and select the appropriate action for your use case. There are many possibilities of what you can do here.

In the case of a field update, there are three steps:

  1. Select the object on which you want to perform the field update
  2. Select the appropriate field
  3. Write in the value or the formula to determine the new value.

One of the really powerful things about field updates is that you are not necessarily limited to updating fields on the workflow object. In many cases, you can update fields on related objects, provided that the workflow object is on the detail side of the relationship. This always works for custom objects, but there are some limitations with standard objects. All of the details can be found by reading Understanding Cross-Object Field Updates. 

Well there you have it: a few simple steps to set up some incredibly powerful, and time-saving functionality, right in your Salesforce org. I hope this helps you get started writing some useful and creative workflow rules to automate your business process!

Have any questions?  Give us a shout!