Search This Blog

Thursday, July 28, 2011

Custom Round Robin Lead Assignment

Have you ever needed to implement round robin lead assignment in Salesforce.com. If you have, then you are familiar with the suggested approach of using assignment rule entries and a couple of custom fields. Although it works, it becomes a pain to manage once the number of members in the round robin start to climb. Other approaches would use custom Apex triggers. I'm not developer, but I'm brave enough to mess with existing apex and this is where a fantastic little free app from the AppExchange comes in.

Currently my favorite approach leverages the Round Robin Record Assignment  app from Force Labs available on the AppExchange. The app is configured to manage the assignment of cases, but with a little tweaking of the triggers and the class, you can get it to manage leads as well.We added a couple of custom fields and work flows and VIOLA!!! You have your custom Round Robin Lead Assignment application that you can also manage from from your iPhone or Blackberry (and you know Android is coming next month).

The app, as we have customized it, allows us to add members (users) to the assignment group with a couple of clicks and removed them by simply setting their Active status in the Assignment Group to "false". You can also schedule the removal and re-insertion of members from and into the round robin cycle. This is useful when a rep is going on vacation. All you have to do is enter the date that he/she will be leaving and the date of their return. The work flows will take care of changing their active status in the assignment group to false and back to true on their scheduled return date.

Before if you wanted to individually assign leads to 20 reps using round robin, segmenting them as Hot and Warm, you would have to create 1 assignment rule entry per user per queue (Hot and Warm queue). That's 40. With this app, you can now do this with 2 rule entries and let the Assignment Group membership handle the actual assignment.Thank you Force Labs.

Here's a link to the setup and configuration of the app.
Round Robin Record Assignment - Setup and Configuration.

Below I have included a screenshot of the Assignment Group screen. You can see the number of users (20) in the group. and you can see what Queues are associated with the group. In this case there is only one. By looking at the Assignment Group Members related list, you can see the members and their statuses, the last  assignment made in the group to the member, as well as any scheduled dales for exiting and re-entering the assignment group.







38 comments:

  1. How were you able to select "Type: Leads" ... ours defaults to "Type: Cases" with no other option.

    ReplyDelete
  2. I modified the Apex Triggers and Class to accommodate Leads in addition to Cases.

    ReplyDelete
  3. Thank you for the quick response Javier. I noticed you posted some review comments on the app on how you set up your custom workflow of dates to set active off,and etc...

    Is there are pre-made app that has all the customization you made...? I mean, this is pretty complex unless you know programming.

    ReplyDelete
  4. Can we contract your services to setup our salesforce? we are looking to do exactly what you have done, but don't have time to figure this out on our own.

    ReplyDelete
  5. Email me your contact info and I will put you in touch with someone that can implement this for you. Javweb@gmail.com

    ReplyDelete
  6. This is awesome. I just tested with cases and it will work perfectly for leads with the proper tweaks.

    I may be interested in some help with the code changes to make it work, though.

    Thanks for this Javier.

    ReplyDelete
  7. You're welcome Joe. Let me know if you need assistance.

    ReplyDelete
  8. I was able to hack the code of the package and make it work for leads (so cool, especially for a non-developer like me).

    However I was trying to create it as a Package (for better administration / best practices), but it fails test coverage when uploading.

    System.DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): Lead, original object: QueueSobject: []

    Any advice on changes to the Class to get it to pass the test for creating the package?

    ReplyDelete
  9. I have added the code for making it work with Leads here: https://gist.github.com/1562280.

    ReplyDelete
  10. As for allowing the picklist to have Leads as well as Cases, you can do that by editing the field on the custom object to add a Leads dropdown as well.

    ReplyDelete
  11. Awesome Evan. Thank you so much. Do you mind if I post your link? There are a lot of people out there that will be very happy you did this. Thanks again.

    ReplyDelete
  12. Javier,

    Can you by any chance make your code available in which you modified this app to deal with leads? I have 5 territory queues of leads and need to round-robin assign those leads to sales reps that belong to those queues.

    Thanks for any help!

    ReplyDelete
  13. Tanya,

    Evan made this code available on GitHub. He modified it to work with both Leads and Cases.
    Make sure to include the change suggested by Andy. You'll see it at the bottom of the page.

    https://gist.github.com/1562280

    ReplyDelete
  14. Hi Javier,

    This is exactly what I am looking for. Unfortunately, I do not have any Apex or coding experience so I am in need of some assistance with the "tweaking" part. Would it be possible for you to help me out?

    Thanks
    Adam

    ReplyDelete
  15. Hi Javier,

    I have seen this application and i want this mechanism for Lead object instead of Cases. So could you please share the code which you modified in order to work with lead object.

    Regards,
    Adi.

    ReplyDelete
    Replies
    1. Here's the modified code to handle both leads and cases. It was provided by Evan Donovan
      https://gist.github.com/1562280

      Delete
  16. I copied Evan's coding exactly as it is listed but I get the following error: Error: Compile Error: unexpected token: trigger at line 135 column 0

    Any thoughts?

    ReplyDelete
    Replies
    1. Both tweaked codes are listed in the same section with light grey headings. remove every thing below row 133 and it should work.

      Delete
  17. This comment has been removed by the author.

    ReplyDelete
  18. When copying the code from https://gist.github.com/1562280 I am receiving this error " Error: Compile Error: Invalid field TempOwnerId__c for SObject Lead at line 13 column 38"

    is it required to create this field some where before updating the apex?

    ReplyDelete
  19. The field is automatically created when installing the original package from the app exchange. If you are simply deploying the code, you will need to create the TempOwnerId__c field on the Lead object. It's a Text(18).

    ReplyDelete
  20. This custom round robin assignment for leads works great! I have it installed and working great in my enterprise edition salesforce instance! There is one issue I have come across while trying to set up our workflows in Salesforce using this.

    Our workflow is as follows: Leads come into the system from the web and are assigned to our 'round robin' queue we have set up using our assignment rules. This works fine. Then the system runs the round robin assignment and assigns the leads to the individual users in the queue. This is also working fine.

    The problem I am having is trying to assign a task. Once the leads have been dispersed to the individual users through the round robin assignment we want the system to assign a task to the lead owner for each lead to remind the individual users that a lead has been assigned to them and to contact that lead.
    I have created a workflow in salesforce that runs when a lead is created that creates an immediate task and assigns it to the 'lead owner' of the lead record. Problem is that the taks keeps being assigned to the default user in the system instead of the individual user that was assigned to the lead by the round robin assignment.
    Now I'm not positive but I believe what is happening is that the workflow rule is being run BEFORE the round robin assignment runs so when the system creates the task and tries to assign it to the 'lead owner' it is still showing the 'round robin queue' as the owner and since you cannot assign a task to a queue it ends up assigning the task to the default owner of the workflow. Can someone confirm/deny that this is the case? And also, does anyone have any suggestions as to how to overcome this hurdle?

    Any help is appreciated!

    Thanks,

    Richard

    ReplyDelete
  21. Hi Richard,

    I am at the same road block, I tried an ISCHANGED function but apparently that won't reference the fields.

    I've put this on the back burner for now, but would like to problem solve it at some point.

    I know ques has an "email owner" function, but im not sure if this working with RRLA.

    ReplyDelete
  22. I feel like such a newb. Can someone please help. I installed the app onto my sandbox environment. I then tried copying the code from Evan Donovan on GIT Hub onto the existing case trigger but it fails with a Error: Compile Error: Trigger name exists on different SObject type: Case at line 3 column 1? So do I need to try and create new triggers or copy the code over in the existing trigger. I really know nothing about the apex code.

    ReplyDelete
  23. Replace the code in the existing trigger with the code from Evan.

    ReplyDelete
  24. Hey guys.

    I am at my wits end here. I cannot, for the life of me, no matter how much I alter the code from Evan, get my production environment to accept the triggers. It simply will not pass the 75% coverage barrier. I have used the exact code from Evan, and modified my apex class to test them, but nothing will work. I am exporting change sets through SF sandbox mode.

    Can anyone, please, help me get this to work?

    ReplyDelete
    Replies
    1. Were you able to get past the test coverage barrier? I am facing the same issue it works out fine in developer edition but has no code coverage when deploying to Prod.

      Delete
  25. Ryan i am having the same issue with getting it out of the sandbox, i cant get the test coverage.

    ReplyDelete
  26. I was curious as to if anyone had any luck fixing the testing class on this yet to get it usable in production?

    ReplyDelete
  27. I just wanted to follow up and say that I've been able to port this over to leads and have it deploy to production successfully. I'll be doing a write-up within the next few days and will have a public link on my G+ profile for anyone else searching for this.

    ReplyDelete
  28. Hi all, Matt was very helpful and provided me with additional code that seems to be working in my developer account: https://github.com/msutkowski/salesforce-roundrobin-mod

    Create the Apex class in develop in Salesforce developer.
    Attach the triggers to the objects (customize for standard lead object, and create --> objects for custom object).

    I am trying to get this deployed. I have done research but do not know how to deploy. Any insights appreciated.

    ReplyDelete
  29. To all having test case coverage issues - Make sure your System Admin account has Assignment Group Active checked then rerun test/deploy.

    ReplyDelete
  30. This comment has been removed by the author.

    ReplyDelete
  31. Hi, I have managed to create the custom trigger and text class based on Matts code, but it flat out won't pass any tests.

    I've checked Assignment Group Active on my users (SysAdmin profile)

    Can anyone help? To test this I'm going to Develop>Apex Test Execution and selecting matt's Test class.

    Error below

    Class: TestMethodClsLeads1
    Method Name: myTest1
    Pass/Fail: Fail
    Error Message: System.DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): Lead, original object: QueueSobject: []
    Stack Trace: Class.TestMethodClsLeads1.myTest1: line 57, column 1

    ReplyDelete
  32. I wish I could help. My knowledge of Apex is enough to allow me to hack other people's code and make it work for our needs. You may want to post the error on the Salesforce Developer forums. I'm sure someone there will be able to point you in the right direction.
    http://boards.developerforce.com/sforce/?category.id=developers

    ReplyDelete
  33. Hi Javier, I managed to get in touch with Matt from the posts above and he's kindly helped me sort it

    ReplyDelete
  34. @MrCairney
    I am facing the same issue when using the code. Can you provide me the solution.

    ReplyDelete
  35. I am having an issue I can't understand. When deploying to my production org I get the following failure:

    # Deploy Results:
    File Name: package.xml
    Full Name: package.xml
    Action: NO ACTION
    Result: FAILED
    Problem: Cannot deploy InstalledPackage in Package Manifest with any other types!

    I have no idea what this means or how to fix it. If anyone can help that would be great.

    ReplyDelete