How to assign Leads in a Round Robin fashion?
May 16, 2013 § Leave a comment
Round Robin Lead Assignment Process summary
This process mainly revolves around a set of users for a particular role (if the round robin needs to be assigned within the users of that role) or can also be completely different set of users from different role hierarchies. The users are set in the Lead Assignment rule using each criterion. Following are some high level requirements before making the round robin functional:
– Create a number field; let’s say “Lead Auto Increment ” and this field is being incremented using a trigger.
– Another formula field is created after this, let’s say “Small Market Assignment” (assuming users are from a role named “Small Market”) which will be as follows:
IF( NumberOfEmployees < 5001, MOD(Lead_Auto_Increment__c, 4), 99999)
– The Small Market Assignment will be populated based on the value of Lead Auto Increment. The MOD function is going to take our Lead Auto Increment value, do a bit of math and return a number in a range we specify. The “4” in the formula above means that it will return a number of 0, 1, 2, or 3. For the sake of our example here, we’re going to assume that we need to implement round robin assignment between 4 users and so the 4 in the formula. Depending on the number of users for our round robin, this value can be changed anytime. The formula is taking our Lead Auto Increment field and creating a Small Market Assignment value.
– Here in the formula, we are taking into consideration a business need for the round robin assignment. Any lead which has “No. Of Employees” less than 5001 will be considered as a criterion to be under the round robin assignment.
– Now, we have the two fields and the trigger in place. But there is a catch here. As we have decided to keep incrementing the Lead Auto Increment value and it is a field under the Lead object, we cannot keep track of the last value of this field in the last lead record created.
– For this, we will need some way to store the latest value of Lead Auto Increment field. Here, custom setting feature of Salesforce comes for our rescue. We will need to create a custom setting and create a field there; let’s say “AutoIncrement” which will store the latest value of the field “Lead Auto Increment”.
For example, we created a new Lead and the trigger updated the value of Lead Auto Increment to 0 since it has number of employees less than 5001 (we can add more conditions in the trigger based on the business requirement). Now, the custom setting field AutoIncrement will store the value 1. Next time, another lead is created/inserted, the Lead Auto Increment value will be 1 and AutoIncrement will be set to 2. This is accomplished using the same trigger.
– Further, if we think proactively, we will also realize that if an existing lead which is already assigned to one of those users (taken into consideration of our round robin assignment rule) is edited and meets our criteria again, then the trigger will update the Lead Auto Increment value and hence the Small Market Assignment value will be updated and finally, the lead will be re-assigned to another user. We don’t want this to happen.
– So, here we can create another field in the same custom setting; let’s say “Users” and store the Salesforce usernames of those users considered to be within our round robin rule. So, the trigger will check the criteria and before it updates the Lead Auto Increment value it will check if the current lead record owner is among these usernames stored in this field “Users”. If it is then the Lead Auto Increment value will not be updated and consequently, the Small Market Assignment value will not populate as well as the Lead Assignment rule will not trigger.
– Also, please make a note that we need to start the value of the custom setting field “AutoIncrement” to 0(zero) in the very beginning. Also, sometimes Admins can forget to set this initial value, it is always a good practice to set this value from the trigger itself initially and keep on updating with the latest value going forward with each lead creation.