How to automate Lead distribution effectively? - Answers - Salesforce Trailblazer Community
Ask Search:
Alexander Piñate ☁️Alexander Piñate ☁️ 

How to automate Lead distribution effectively?

Hi Team,

This is the business case:

Our sales reps need to have 200 leads on their name (excluding DQs and Qualified). 
We need to automate the Lead dsitribution from one central Queue to all the reps. The Lead distribution will top up a rep with leads if they are below the 200 thereshold. This would be automatic and constant. 

Any ideas on how to approach this? I am assuming process builder and flows may be involve.

Thanks for the help.
Best Answer chosen by Alexander Piñate ☁️
Amnon KruviAmnon Kruvi
Hi Alexander, 

I'm afraid flows probably won't help here. What you need is an Apex trigger on leads, which runs each time a lead's status changes. It would then recount however many active leads the owner still has, and fetch 200 - x leads from the queue for reassignment. You'd also need a mechanism, which could be a flow, to "seed" new users. 

All Answers

Amnon KruviAmnon Kruvi
Hi Alexander, 

I'm afraid flows probably won't help here. What you need is an Apex trigger on leads, which runs each time a lead's status changes. It would then recount however many active leads the owner still has, and fetch 200 - x leads from the queue for reassignment. You'd also need a mechanism, which could be a flow, to "seed" new users. 
This was selected as the best answer
Alexander Piñate ☁️Alexander Piñate ☁️
Apex is not my strong skill tho. Lighting flows and process builders no problem at all!
Amnon KruviAmnon Kruvi
The problem with a flow is, let's say you update 100 leads to change their status. You now need to reassign 100 leads to those leads owners.  Due to the dynamic limit of the query, you'll need to put it in a loop and query 100 times - and therefore break the governor limits. With Apex it'll be 1. It also will not be able to handle any deletion events. 

There are AppExchange products that may help you with lead assignment as well, or you could also approach a contractor to build it.