+ Start a Discussion
Yamini BathulaYamini Bathula 

Round robin Lead Assignment

Hi guys,

I have created a round robin lead assignment in salesforce using auto  number and then a formula on it to divide the auto number with number of users. But it is not evenly disctributing among the sales people as exoected. I want the round robin to work only on a subset of leads but not all. Is there any way to achieve this?

 
buggs sfdcbuggs sfdc
HI yamini,

This may help you out,or else you can provide code snippet here,we will try to look at it.
 
To assign leads (or cases) that are either manually created or created using Web to Lead (or Case). Follow the instructions below:

The first steps for lead or case assignment is to create two custom fields that can be included in the page layouts for users or hidden as they are strictly for the assignment mechanism based on the custom formula. The instructions below assume the setup is for leads.
 
1. Create an auto number field in leads called "Lead Number" that spans 0 decimal places and had the format "{0}" (exclude the inverted commas). Below are the steps to create Auto number field:

a) Click on Setup | Customize | Lead | Field.
b) Scroll down and click on “New” button on “Lead Custom Fields & Relationships”.
c) Scroll down and select “Auto Number” radio button.Enter “Field Label” (eg – Lead Number) with that spans 0 decimal places and had the format "{0}" (exclude the inverted commas). 
d) Click on Next for “Field-Level Security for Profile”Click on “Save” to include it different Page Layout Name.
2. Create a custom formula field with return type number in leads called "Round_Robin_ID" and use the formula:
MOD(VALUE(Lead_Number__c) ,3) +1
3. Use the value of this formula field in your lead assignment rules to assign lead records to different queues or users:
Round_Robin_ID = 1 is assigned to Queue A (User 1)
Round_Robin_ID = 2 is assigned to Queue B (User 2)
Round_Robin_ID = 3 is assigned to Queue C (User 3)

 
Explanation of the process:
The following formula example for leads assumes you have 3 lead queues and you want to assign an equal number of incoming leads to each queue. You can also assign cases using a similar formula.

MOD(VALUE(Lead_Number__c) ,3) +1 is the formula for a custom formula field named Round_Robin_ID that assigns each lead a value of 1, 2, or 3. This formula uses a custom auto-number field called Lead Number that assigns each lead a sequential number starting with 1. The MOD function divides the lead number by the number of lead queues available (3 in this example) and returns a remainder of 1, 2, or 3.

Remember: 
It will not work on the existing records. In order to make the rule trigger for existing records you should "Mass" update the records.
If you are creating a record manually, you can check the "Assign using active assignment rule" under options so that the record follows the assignment rule at the time of creation.



 
Lokesh KumarLokesh Kumar
Hi Yamani,

Please try below links to achieve this .

https://gist.github.com/eskfung/f342b47ecc0849deb0cb

http://salesforce.stackexchange.com/questions/53235/lead-assignment-round-robin-based-on-lead-source

https://help.salesforce.com/articleView?id=000004000&type=1

Hope it will help you.
Manish NelekarManish Nelekar
Hi Yamini,

Instead of using the auto increment field, you need to write a trigger on Lead which will increment the number after checking the record type
And then use that custom field instead of auto number for mod function.
Trigger should be on insert and not on update.

Something like below - 
trigger xyz on Lead(before insert) {
Id rtId=  Schema.SObjectType.Lead.getRecordTypeInfosByName().get('Your Rec Type Name').getRecordTypeId();
Lead l = [Select customfield__c From Lead Where RecordTpeId =: rtId OrderBy customfield__c Limit 1 ]
Integer lastCount = l.customfield__c;
for(UrObject ob: Trigger.New) {
if(ob.RecordTpeId == rtId) {
lastCount = lastCount +1;
ob.numberField = lastCount;
}
}
}

There are many validation checks you need to put but this is just an overview of how it will look.