function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Eran VizelEran Vizel 

Role based notification workflow

Hi all,

I want to notify ownership change of a lead from owner in a certain group of roles to an owner withhin another group of roles. For this I created this not very scalable workflow: 

ISCHANGED( Lead_Owner_Role__c ) && 

( PRIORVALUE(Lead_Owner_Role__c ) = "VP_Business_Development" 
|| PRIORVALUE(Lead_Owner_Role__c ) = "Director_Business_Development" || PRIORVALUE(Lead_Owner_Role__c ) = "Enablement_Manager" || PRIORVALUE(Lead_Owner_Role__c ) = "Technology_Partners" || PRIORVALUE(Lead_Owner_Role__c ) = "Channel_Sales_Manager" ) 

&& 

( Lead_Owner_Role__c = "APAC_Sales_Director" || Lead_Owner_Role__c = "APAC_Sales_Representitive" || Lead_Owner_Role__c = "Eastern_Region_Sales_Director" || Lead_Owner_Role__c = "East_Region_Sales_Representitve" || Lead_Owner_Role__c = "South_Eastern_Sales_Director" || Lead_Owner_Role__c = "South_Eastern_Sales_Representitive" || Lead_Owner_Role__c = "TriState_Eastern_Sales_Director" || Lead_Owner_Role__c = "TrisState_Eastern_Sales_Representative" || Lead_Owner_Role__c = "EMEA_Sales_Director" || Lead_Owner_Role__c = "EMEA_Sales_Representitive" || Lead_Owner_Role__c = "Midwest_Canada_Region_Sales_Director" || Lead_Owner_Role__c = "Canada_Sales_Director" || Lead_Owner_Role__c = "Canada_Sales_Representative" || Lead_Owner_Role__c = "Midwest_Canada_Region_Sales_Representitive" || Lead_Owner_Role__c = "Midwest_Region_Sales_Representative" || Lead_Owner_Role__c = "South_Central_Region_Sales_Director" || Lead_Owner_Role__c = "South_Central_Region_Sales_Representative" || Lead_Owner_Role__c = "Telecommunications_Sales_Manager" || Lead_Owner_Role__c = "Western_Region_Sales_Director" || Lead_Owner_Role__c = "Western_Region_Sales_Representitve")

Is there a better way to do it?

Thank you,
Eran
srlawr uksrlawr uk
ha! I really like this question, because it is a bit of a head scratcher, and also because, although you have achieved something technically - you are looking for a better way to complete it, which means you are clearly someone who likes to be proud of their work, and does a good job. Kudos to you.

The funny thing is, looking at all your roles, I can't really think of a "better" way to do what you are after. All your role names are quite singular (so you can't get away with using CONTAINS to blat out a whole group of them). I guess, also, there are a bunch of other roles in the org that don't even come into this equation which have to be "avoided" in the later part of the evaluation.

The only way I can think to "tidy up" the workflow evaluation is to literally shift the formula into.... a formula field!! You could take the second half of the evaluation and stick it behind a checkbox on Lead called "With Sales Dept" (or whatever makes sense) and then put that long chain of roles in there... this means in the formula above, you only have to evaluate that one checkbox field instead. Literally doesn't make any difference to the complexity over-all, but it denormalises some of the logic onto the actual object to which is depends.

The only other thing I can think is you could use a CASE statement to reduce the number of "Lead_Owner_Role__c" and || you have to use.. something like:
 
CASE(Lead_Owner_Role__c,
"APAC_Sales_Director", true,
"APAC_Sales_Representitive", true,
"Eastern_Region_Sales_Director", true,
"East_Region_Sales_Representitve", true,
"South_Eastern_Sales_Director", true,
"South_Eastern_Sales_Representitive", true,
, false)
which is a bit tidier, and easier to drop new roles into... 

(there is some complexity around cases using/returning booleans that you might need to check out, but I think that should work)
Case function: https://help.salesforce.com/apex/HTViewHelpDoc?id=customize_functions_a_h.htm&language=en_US#CASE (https://help.salesforce.com/apex/HTViewHelpDoc?id=customize_functions_a_h.htm&language=en_US#CASE)


Those two points are literally all I got! Hope it helps, or at least encourages you with your chosen approach!! happy new year.