Does anybody know how the "includes" and "excludes" operators work when setting up rule criteria for workflow rules?
The only documentation I've found on this is located at https://help.salesforce.com/articleView?id=filter_operators.htm&type=0&language=en_US&release=204.14 - this is good documentation, but since it is filed under Reports & Dashboards I get a little uneasy that it might be inaccurate.
My understanding is that the "includes" and "excludes" operators are only available when the field you've chosen is a multi-select picklist field (as the documentation states). These operators seem to work similarly to the "equals" and "not equal to" operators, except that multi-select picklist values are stored in a semi-colon delimited string that is split into multiple values when the workflow rule does its evaluation.
I've done some testing and the results I'm seeing are different than what I was expecting, and the documentation doesn't make it very clear. So here we go:
Working Scenario - "Includes"
From the documentation linked above:
Available when you choose a multi-select picklist as the selected field. Use this operator to find records that include one or more of the values you enter.
There exists a custom multi-select picklist field (Custom_Picklist__c
) on the Lead with the values: A, B, C, D.
There exists a custom checkbox field (Checkbox__c
) on the Lead.
We create a Workflow rule that sets the Checkbox__c
field to true every time a lead is created or edited and Custom_Picklist__c includes A, C
Results:
Lead #1: Custom_Picklist__c = null
& Checkbox__c = false
Lead #2: Custom_Picklist__c = B
& Checkbox__c = false
Lead #3: Custom_Picklist__c = A
& Checkbox__c = true
Lead #4: Custom_Picklist__c = A; B; C
& Checkbox__c = true
All results evaluate as expected. The record only needs one of the values to be selected in order for the workflow to fire.
Broken(?) Scenario - "Excludes"
From the documentation linked above:
Available when you choose a multi-select picklist as the selected field. Use this operator to find records that do not contain any values that match the ones entered.
Same as above - Custom_Picklist__c
& Checkbox__c
custom fields exist on the Lead.
We create a Workflow rule that sets the Checkbox__c
field to true every time a lead is created or edited and Custom_Picklist__c excludes A, C
Results:
Lead #1: Custom_Picklist__c = null
& Checkbox__c = true
Lead #2: Custom_Picklist__c = B
& Checkbox__c = true
Lead #3: Custom_Picklist__c = A
& Checkbox__c = true
Lead #4: Custom_Picklist__c = A; B; C
& Checkbox__c = false
Results do not evaluate as expected. I did not expect to see Lead #3's checkbox field set to true. The workflow rule is set to only act on records where the multi-select excludes A, C - I expected that to mean that the record would be ignored even if only one of those values is selected.
Am I misunderstanding the documentation? Or did I find a workflow bug?
Edit: I did some more testing using multi-select picklists with "equals" and "not equal to" and so I wanted to share those results as well.
Working Scenario - "Equals"
Same as above - Custom_Picklist__c
& Checkbox__c
custom fields exist on the Lead.
We create a Workflow rule that sets the Checkbox__c
field to true every time a lead is created or edited and Custom_Picklist__c equals A, C
Results:
Lead #1: Custom_Picklist__c = null
& Checkbox__c = false
Lead #2: Custom_Picklist__c = B
& Checkbox__c = false
Lead #3: Custom_Picklist__c = A
& Checkbox__c = true
Lead #4: Custom_Picklist__c = A; B; C
& Checkbox__c = false
Results are as expected, I guess. The "equals" operator is different than "includes" because Lead #4 evaluates to false. The picklist must equal A, C (or just A or just C) and cannot contain another other values.
Broken(?) Scenario - "Not Equal To"
Same as above - Custom_Picklist__c
& Checkbox__c
custom fields exist on the Lead.
We create a Workflow rule that sets the Checkbox__c
field to true every time a lead is created or edited and Custom_Picklist__c not equal to A, C
Results:
Lead #1: Custom_Picklist__c = null
& Checkbox__c = true
Lead #2: Custom_Picklist__c = B
& Checkbox__c = true
Lead #3: Custom_Picklist__c = A
& Checkbox__c = false
Lead #4: Custom_Picklist__c = A; B; C
& Checkbox__c = true
Lead #5: Custom_Picklist__c = A; C
& Checkbox__c = true
This one blew my mind and I had to include even more results here because it's just damn confusing. If the picklist only has A selected or only has C selected, the workflow works as expected. I can maybe understand why it evaluates to true if A, B, and C are selected since B is not part of the not equal to criteria.
But A, C evaluates to true? How? Those are specifically the values I'm setting the criteria for not equal to.