In the article Understanding Workflow Rule criteria we left out the section 'Add Filter Logic'. Let us explore now and see how can we utilize this feature in Force.com platform.
The Workflow Rule Criteria in Force.com platform gives two different choices to run the rule - 1. criteria are met. 2. formula evaluates to true.
In the 1st choice, when we are defining the criteria, as you can see there are multiple rows we can fill in. At the end of each row, you see an 'AND' literal. That means criteria specified in each row is logically ANDed to come up with the final criteria.
Let us take a simple example.
Say our requirement is to find all Opportunities for new customers with amount is more than 10000.
1st Row - Opportunity: Type equals New Customer
2nd Row - Opportunity: Amount greater than 10000
This translates the rule criteria into -
(Opportunity: TypeEQUALSNew Customer) AND (Opportunity: AmountGREATER THAN10000)
which is in other words, (Row 1 AND Row 2)
The rule criteria works fine and we find the records we want. Now let us change our requirement a bit.
Say our requirement is to find all Opportunities for new customers with amount is more than 10000, and all other opportunities if the amount is more than 25000 regardless of new or existing customer.
1st Row - Opportunity: Type equals New Customer
2nd Row - Opportunity: Amount greater than 10000
This would translate to -
(Opportunity: TypeEQUALSNew Customer) AND (Opportunity: AmountGREATER THAN10000) AND (Opportunity: AmountGREATER THAN25000)
or (Row 1 AND Row 2 AND Row 3)
As you can see, this doesn't result into exactly what we are after. Instead, the result of this would be exactly same as the 1st expression. This is where 'Filter Logic' is applied to get the right result. Click on the 'Add Filter Logic' link at the bottom. You will see the following -
See the Filter Logic that says 1 AND 2 AND 3. We change this into (1 AND 2) OR 3 to get our result. Now the rule criteria changes into -
((Opportunity: TypeEQUALSNew Customer) AND (Opportunity: AmountGREATER THAN10000)) OR (Opportunity: AmountGREATER THAN25000)
Thus getting us all opportunities of amount more than 25000 along with new customer opportunities with amount more than 10000.
And we have Filter Logic from the previous step as (1 AND 2) OR 3. Now we need to add the 4th row into the logic as per our new requirement.
We have 2 expressions separated by an OR. We need to make sure both returns the opportunities that are only at negotiating stage. So ideally we AND our 4th row into both, giving us (1 AND 2 AND 4) OR (3 AND 4). We could also take out the 4 outside and come up with ((1 AND 2) OR 3) AND 4
That is how filter logic is used while creating workflow rules. This same filter logic is useful while filtering report data as well. As you can see it can get tricky with complex filtering requirements. Choosing the right filter and grouping them in proper parentheses will make it easier.
Happy cloud computing using Salesforce!
The Workflow Rule Criteria in Force.com platform gives two different choices to run the rule - 1. criteria are met. 2. formula evaluates to true.
In the 1st choice, when we are defining the criteria, as you can see there are multiple rows we can fill in. At the end of each row, you see an 'AND' literal. That means criteria specified in each row is logically ANDed to come up with the final criteria.
Let us take a simple example.
Say our requirement is to find all Opportunities for new customers with amount is more than 10000.
1st Row - Opportunity: Type equals New Customer
2nd Row - Opportunity: Amount greater than 10000
This translates the rule criteria into -
(Opportunity: TypeEQUALSNew Customer) AND (Opportunity: AmountGREATER THAN10000)
which is in other words, (Row 1 AND Row 2)
The rule criteria works fine and we find the records we want. Now let us change our requirement a bit.
Say our requirement is to find all Opportunities for new customers with amount is more than 10000, and all other opportunities if the amount is more than 25000 regardless of new or existing customer.
1st Row - Opportunity: Type equals New Customer
2nd Row - Opportunity: Amount greater than 10000
3rd Row - Opportunity: Amount greater than 25000
This would translate to -
(Opportunity: TypeEQUALSNew Customer) AND (Opportunity: AmountGREATER THAN10000) AND (Opportunity: AmountGREATER THAN25000)
or (Row 1 AND Row 2 AND Row 3)
As you can see, this doesn't result into exactly what we are after. Instead, the result of this would be exactly same as the 1st expression. This is where 'Filter Logic' is applied to get the right result. Click on the 'Add Filter Logic' link at the bottom. You will see the following -
See the Filter Logic that says 1 AND 2 AND 3. We change this into (1 AND 2) OR 3 to get our result. Now the rule criteria changes into -
((Opportunity: TypeEQUALSNew Customer) AND (Opportunity: AmountGREATER THAN10000)) OR (Opportunity: AmountGREATER THAN25000)
Thus getting us all opportunities of amount more than 25000 along with new customer opportunities with amount more than 10000.
Now let us change our requirement once again.
Say our requirement is to find all Opportunities for new customers with amount is more than 10000, and all other opportunities if the amount is more than 25000 regardless of new or existing customer, only if the opportunities are at negotiation stage.
1st Row - Opportunity: Type equals New Customer
2nd Row - Opportunity: Amount greater than 10000
3rd Row - Opportunity: Amount greater than 25000
4th Row - Opportunity: Stage equals Negotiation/ReviewAnd we have Filter Logic from the previous step as (1 AND 2) OR 3. Now we need to add the 4th row into the logic as per our new requirement.
We have 2 expressions separated by an OR. We need to make sure both returns the opportunities that are only at negotiating stage. So ideally we AND our 4th row into both, giving us (1 AND 2 AND 4) OR (3 AND 4). We could also take out the 4 outside and come up with ((1 AND 2) OR 3) AND 4
That is how filter logic is used while creating workflow rules. This same filter logic is useful while filtering report data as well. As you can see it can get tricky with complex filtering requirements. Choosing the right filter and grouping them in proper parentheses will make it easier.
Happy cloud computing using Salesforce!
No comments:
Post a Comment