Custom Round Robin Record Assignment in Salesforce
I recently had to rewrite a bunch of record assignment rules for a custom object in Salesforce. Previously, the object was assigned via a workflow rule with a filter that read from a hidden Auto Number field. The workflow rule triggered a field update that would change the owner of the record.
What I had to do was rewrite the rule so that it would assign the records evenly to two groups of users based on certain criteria in the record.
Scenario:
- The custom object needs to be assigned to two groups of users via round robin record assignment.
- Group one has 5 users and will receive records for the Medium product.
- Group two has 2 users and will receive records for the Small product.
- The assignment must be a true Round Robin and must load balance correctly. (i.e. each user in group one must receive 20% of all mediums and each user in group two must receive 50% of all smalls.
Solution:
You can pull this off with just one auto number field on the object, but you need two formula fields- one for each product type (medium and small). Name them something obvious like Medium Assignment Number, and Small Assignment Number.
Using the regular MOD(VALUE(AUTONUMBER FIELD) expression used for Round Robin assignment- Set the true value to be the number of users in that group, and the false value to be a number greater than the number of users in the rotator.
In this case, records are getting assigned based on the product, which is a picklist value. Adding a simple IF(ISPICKVAL(PRODUCT TYPE) expression in front of the MOD(VALUE will accomplish this.
The new rotator formula will look like this
IF(ISPICKVAL(PRODUCT, "PRODUCT TYPE") , MOD(VALUE(AUTONUMBERFIELD), # of users in group 1), # that is greater than the number of users in the rotator)
Add a similar formula field for the second group of users in the rotator.
You can then add a workflow rule and a field update for each user. The criteria can simply be 'Medium Assignment Number' or whatever you named your new field = #, etc... Make sure you start at zero!
- User 1: Medium Assignment # = 0
- User 2: Medium Assignment # = 1
- User 3: Medium Assignment # = 2, etc...
Follow-Up
I've received a few questions about this in the Developerforce discussion boards. Hopefully the following will clear up some confusion around how the MOD function works.
The formula uses the AutoNumber field and assigns each record a sequential number starting with 1. The MOD function divides the number by the number of users and returns a remainder (starting with zero) into the custom field.
In my example, If I have two reps- each receiving the Small Product Type, I would set up the formula to be:
IF(ISPICKVAL(PRODUCT, "Small") , MOD(VALUE(AUTONUMBERFIELD), 2)
This will take the value in the AutoNumber field, divide it by two, and then return a remainder of 0 or 1.
So- if record X is assigned an AutoNumber of 1:
1/2 = .5
The intiger part is 0.
0 x 2 = 0
1-0 = 1.
1 is your remainder.
If record Y is assigned an AutoNumber of 88:
88/2 = 44
The intiger part is 44.
44 x 2 = 88
88-88 = 0.
0 is your remainder.
Since there are only two users in this group, all remainders will either be 0 or 1. You then set your workflow rules to assign records with a value of 0 to user 1 and records with a value of 1 to user 2.
** If anyone has any questions on how to set this up in their org, I'd be more than glad to help. Shoot me an email - david [at] duckyboard [dot] com