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

Limit number of leads a User can own


Have a requirement that consists of having only "x" number of leads being owned by a person at any point in time. if the count drops due to conversion, etc then more leads will automatically be added in, else if rep attempts to add one too many then theyare not able to. 

Blake TanonBlake Tanon
First, you'll need to pick a 'master' user to hold all unassigned leads.  
Second, what are the criteria for a lead (certain stage, etc..., or just all leads)?
Third, should leads be assigned immediately on creation or can a batch run every 30min,hour, etc...?

Just off the top of my head, you could probably start with a custom field(number) on User called 'Assigned_Leads__c'.
Right a trigger to get a list of all users that may own leads, and assign based on availability.  Also in this trigger, do not let a lead owner change if the owner has 100% full lead count.  You'll need the trigger to update the Assigned_Leads__c field when a lead is created, deleted, converted.