Use default Lead Assignment rules

edited December 13, 2019 in Ideas
It's not possible to have a Lead form submitted by SKUID via sites to automatically run assigment rules. To solve this I created a trigger + class that runs assignment rules if a custom checkbox (hidden from users) are set to true. Maybe this quick fix can bee of use to someone else. See the code below: Trigger ------------ trigger ReassignLeads on Lead (after insert, after update) { List lIds=new List(); For (lead{ if (l.IsConverted==False && l.Run_Assignment_Rules__c==true){ lIds.add(l.Id); } } if (AssignLeads.assignAlreadyCalled()==FALSE){ system.debug('Assign already called? '+AssignLeads.assignAlreadyCalled()); AssignLeads.Assign(lIds); } } ----- Class ------- public with sharing class AssignLeads { static testMethod void AssignLeadTest() { //Basic code coverage test code - improve with bulk + asserts List TestlIds=new List(); Lead newLead = new Lead(company='Testco', LastName='TestLast', FirstName='TestFirst', Run_Assignment_Rules__c=true); test.startTest(); insert(newlead); test.stopTest(); TestlIds.add(newLead.Id); if (AssignLeads.assignAlreadyCalled()==FALSE){ AssignLeads.Assign(TestlIds); } } public static Boolean assignAlreadyCalled=FALSE; public static boolean assignAlreadyCalled(){ return assignAlreadyCalled; } @future public static void assign(List lIds){ assignAlreadyCalled=TRUE; List leads=[SELECT Id FROM Lead WHERE Id IN: lIds]; For (lead l:leads){ Database.DMLOptions dmo = new Database.DMLOptions(); dmo.assignmentRuleHeader.useDefaultRule= true; l.setOptions(dmo); l.Run_Assignment_Rules__c = false; // reset the checkbox } update(leads); } }
0 votes

Implemented · Last Updated


  • Anna WiersemaAnna Wiersema 🛠️ 
    edited December 13, 2019
    Thanks for sharing, Peter! This is awesome.
  • edited March 2, 2017
    This has been implemented as of Skuid 4.15.8 - it is now possible to specify, at a row level, whether or not to run default Lead/Case Assignment Rules, as well as (for Leads only) to specify a particular Assignment Rule to run (if you have multiple defined in your org).

    Support for various other DMLOptions has been added as well. 

    See the release notes for Skuid 4.15.8 for more details (available from the Skuid releases page).
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!