Tuesday, November 27, 2012

Understanding Workflow Rule criteria in Force.com

In the article Creating Workflow Rules we learnt the steps involved in creating workflow rules in Force.com platform. In this article let us explore the step of defining the rule criteria. 

In Step 2 while creating the workflow rule, after you enter the rule name and description, you have 2 sections - Evaluation Criteria and Rule criteria as shown below. 



They both work together to determine when the rule is executed. Let us go in the reverse direction. First let us see what is Rule Criteria and then Evaluation Criteria.

Rule Criteria - Rule Criteria defines when to trigger the rule. You can define this based on the combination of field values or based on a formula evaluation. 

Let us take a very simple example to understand this better. 


  • Say you have an object called Invoice with a field named Status of values 'Open' and 'Closed'. 
  • You want to perform some action when the status of each invoice record is closed.
  •  You would define the rule criteria as 'Status' equals 'Closed'
This defines the criteria to trigger the rule when status is changed to closed for invoice record. However it is not that straight forward. As we can see below the evaluation criteria controls this further.

Evaluation Criteria - This defines when to evaluate the rule criteria. Only when this criteria is met, the rule criteria is evaluated and triggered if met.  There are 3 different choices.

  • created - This indicates evaluate the rule criteria each time a record is created. That means rule is evaluated only once when record is created. Hence in our example this option would indicate each time when an Invoice record is created, since evaluation criteria is met, rule criteria is evaluated and hence checked if the Invoice is created with 'Closed' status. If it is not created with 'Closed' status, no action is performed. Rule is never triggered again for this record even if the invoice changes to 'Closed' later on.
  • created, and every time it's edited - This indicates evaluate the rule criteria each time a record is created and updated. Hence in our example this option would check if the Invoice status is 'Closed' when a record is created as well as each time the record is updated.
  • created, and any time it's edited to subsequently meet criteria - This is same as the above but the difference is it makes sure when the record is updated the rule criteria is really met as part of the update. In other words, it ignores the record edits that are not relevant to the rule criteria. In our example, say Invoice Status is updated from 'Open' to 'Closed' -  Rule criteria is evaluated and triggered since status was changed to 'Closed'. Now say Invoice record is updated again to correct the customer address zip code - Rule criteria is not evaluated though the Invoice status is 'Closed'. Platform will understand that the update is not related to the status change.
That is how we set the rule criteria. On this step there is one more item which is part of rule criteria called 'Add Filter Logic'. We will cover this in the next article.

Happy cloud computing using Salesforce!

No comments:

Post a Comment