[SalesForce] Apex dynamically assign new records to users using trigger

I'm a young Apex developer. I have a quick question:

I would like to dynamically assign new records to users using an Apex trigger. As we know, every new created records are automatically assigned to the current logged in user.

I am trying to create a trigger that assigns the leads between the 2 users equally. The solution should count the number of leads assigned to each user, so that we have similar number of leads assigned to each user.

For example:
– You have User C and User D
– You mass insert 7 lead records
– Leads 1, 3, 5 and 7 are assigned to User C
– Leads 2, 4 and 6 are assigned to User B

Best Answer

What you're looking for is called "round robin" assignment.

1) If you want to custom build it, you can find the approach on a similar question that I've answered for Cases and Accounts here. You would need to do the same thing for the users and leads.

2) There is an app called "Round Robin Record Assignment" on the appexchange, I personally haven't tried it, but looks like it does what you need and it's free.

3) You can also achieve this by creating a couple of custom fields and assignment rules. A very good example can be found here

Related Topic