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
smitha george 5smitha george 5 

Writing an Apex Trigger

Can you write an apex trigger to assign all incoming leads in a Round-Robin fashion to users based on the following criteria
1.If the lead RecordType = ‘US Lead’, then assign the lead to users with country = ‘USA’
2.If the lead RecordType = ‘International’, then assign the lead to users with Country != ‘USA’
For eg., if there are only 3 users(User1,User2,User3) with country = ‘USA’ in the system then the first lead with RecordType = ‘US Lead’ will be assigned to User1, Second lead with RecordType = ‘US Lead’ will be assigned to User2 and so on.
The same logic applies to international leads.
Thanks in Advance..
Hi Smitha,
I cannot help you in writting a code. As this is not the right place for these kind of queries.
Though, you can try creating one using following link:
Hope this will give you an idea of achieving your task.

Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help.
I think ProCore Resources has an app that does that.

It's a bit more complicated than just a trigger.  You need to decide if it's a round robin for ALL users or not.  If it's not all user's then you have to modify the User object somehow to keep track of who is eligible for consideration, and who the next (or last) user is.

Amit Chaudhary 8Amit Chaudhary 8
Hi smitha george 5 ,

I will recommend you to use Lead Assignment rule for same. You can do same without Trigger
smitha george 5smitha george 5
Thanks for reply Amit...
My requirement is to write a Trigger ..So please help me on this 
Hi Samitha,
You have to understand the flow here. The functionality you are trying to achieve is not possible through trigger. 
You have to use combination of assignment rules, queues and some cutom logic which would perform round robin.