Reply
Regular Visitor
benras
Posts: 2

Workflow rule to run active lead assignment rules

Is it possible to create a workflow rule that updates the lead owner field using active lead assignment rules?  I know you can run a workflow rule that updates the lead owner field to a specific user, but I don't see an option that allows me to update lead owner based on active lead assignment rules.
Super Contributor
jkucera
Posts: 730

Re: Workflow rule to run active lead assignment rules

No, but you can use a trigger to fire assignment rules.

 

In Apex you can use DMLOptions to run assignment rules upon update. From the Apex Code Developers Guide:

Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule= true;

Lead l = new Lead(company='ABC', lastname='Smith');
l.setOptions(dmo);

insert l;

 Instead of inserting, you'd be updating the lead though.

John Kucera
Product Manager - Salesforce Chatter
Free Chatter Unfollow Rules App
Regular Visitor
benras
Posts: 2

Re: Workflow rule to run active lead assignment rules

Thanks for your response John. 

 

I'm specifically trying to get the lead assignment rules to fire everytime one particular user changes the lead status of one of his leads.  I know he can go in and mark the checkbox to make this happen, but we want it to be automatic.

 

Any thoughts on how we could specifically make this work?

 

Thanks,

Ben

Super Contributor
jkucera
Posts: 730

Re: Workflow rule to run active lead assignment rules

You'd use the above in a trigger.  This syntax should get you pretty close:

 

trigger myleadtrigger on Lead (before update){ for (Integer i=0; i<trigger.new.size(), i++){ if (trigger.old[i].status!=trigger.new[i].status){ Database.DMLOptions dmo = new Database.DMLOptions(); dmo.assignmentRuleHeader.useDefaultRule= true; trigger.new[i].setOptions(dmo); } } }

 

 

 

 

 

John Kucera
Product Manager - Salesforce Chatter
Free Chatter Unfollow Rules App
Regular Contributor
SDSFuser
Posts: 15

Re: Workflow rule to run active lead assignment rules

Hi,

 

Here is my trigger and it does not fire:  It is updating the compnay name but not firing the rules.

 

It does update he Company Name but DOES NOT fire the rules

 

trigger LeadRUnAssignRules on Lead (before update){

for (Integer i=0; i<trigger.new.size(); i++){
  if (trigger.new[i].Admin_CampaignRouteToRep__C = TRUE){
    trigger.new[i].Company = 'Updated From Trigger';
    Database.DMLOptions dmo = new Database.DMLOptions();
    dmo.assignmentRuleHeader.useDefaultRule= true;
    trigger.new[i].setOptions(dmo);

  }
}
}

Thank You
Regular Contributor
gwp
Posts: 15

Re: Workflow rule to run active lead assignment rules

[ Edited ]

I'm having an identical problem.

I've created a lead assignment rule to assign a lead to a que. The rule is simple and active, there is one conditional : if lead record type = A then assign to que B.

When a user creates a lead, updates it, or a lead is received from the web I want this to run. SO I created a trigger which seems to get hit but the rules refuse to run (as I understand them):

trigger ActiveLeadAssignment on Lead (before insert, before update) {
//When a lead is updated this will force the default (active) lead assignment rules to run
//no matter who the current owner is or how it was entered into the system
for (Lead l : Trigger.new) {
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule= true;
dmo.emailHeader.triggerUserEmail = true;
dmo.emailHeader.triggerOtherEmail = true;
l.setOptions(dmo);
}
}

The lead is not getting assigned to the QUE under any circumstance (web to lead, user entry, user update).

Thanks!

Matt

Message Edited by gwp on 12-18-2009 07:58 AM
Super Contributor
jkucera
Posts: 730

Re: Workflow rule to run active lead assignment rules

I forgot a critical line in my example:

Database.update()

 

Here's what the revised update example would look like:

 

trigger myleadtrigger on Lead (before update){
for (Integer i=0; i<trigger.new.size(), i++){
if (trigger.old[i].status!=trigger.new[i].status){
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule= true;

trigger.new[i].setOptions(dmo);
database.update(trigger.new[i]);
}
}
}

 

gwp - in your example, add this at the bottom of the for loop:

 

database.update(l);

 

John Kucera
Product Manager - Salesforce Chatter
Free Chatter Unfollow Rules App