How can I get leads from specific companies, i.e., leads meeting specific filter criteria, to skip assignment rules and go directly to a designated rep?

Currently my trigger assigns named account leads based on the email domain of the incoming lead and the named account.

Here's the code I'm using:

trigger NamedAccountOwner on Lead (after insert, after update) {
public list<Lead> LeadsToUpdate = new List<Lead>();

Map<string,Id> DomainAccountMap = new Map<string,Id>();
for (Account a :[SELECT ownerID, email_domain__c FROM Account WHERE email_domain__c != null and Named_Account__c = true])
{DomainAccountMap.put(a.email_domain__c, a.ownerId);}

for(integer i=0; i < trigger.new.size();i++){
If(trigger.isinsert || (trigger.isupdate && trigger.new[i].temp__c == 6789 && trigger.old[i].temp__c != 6789)){

ID owner = DomainAccountMap.get(trigger.new[i].email_domain__c);
If(owner != null){

LeadsToUpdate.add(new Lead(Id=trigger.new[i].Id, Ownerid = owner));


If(leadstoupdate.size() > 0){update LeadsToUpdate;}else{}
  • 3
    Can you turn this into a question? – Keith C Apr 8 '14 at 16:38
  • Are you trying to override the Setup | Lead |Assignment rules using this after insert/update trigger? If yes, Lead Assignment rules will always run after the Lead 'after trigger' and to change the default assignments will require using an @future method. – cropredy Apr 8 '14 at 18:47

There is a dml option to skip assignment rules.

Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule= false;
  • Yeah, but you cannot set that option from within the operation being performed. – Adrian Larson Mar 15 '17 at 16:28
  • Lead ids to @future method. There, you would: 1) Clone, 2)Delete, 3) Re-insert with operation set. – Matthew McKinley Mar 15 '17 at 17:21

I'd add a checkbox to mark the leads that were assigned by the trigger, and set as criteria in the assignment rule that - checkbox=false.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.