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
mhamberg1mhamberg1 

disable Web to lead assignment rules

I wrote a trigger that figures out who the Lead owner should be based on some rules that we have.

 

When I execute this via web-to-lead, my trigger assigns the appropriate person but in the order of operations after that, Salesforce runs the Lead 'Assignment Rules.'

 

Since I have no formal 'assignment rules' set up, the system assigns every lead to the default lead owner. This only happens in the web to lead scenario - when I manually create a lead or bulk load them with the dataloader, they get assigned properly.

 

Is there a way in Apex to tell the system not to run the assignment rules or is there a way around this situation?

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
mhamberg1mhamberg1

I finally figured this out! The clue was looking at Salesforce's order of execution found here.

 

The key is:


"10. If there are workflow field updates, the record is updated again

11. If the record was updated with workflow field updates, before and
after triggers fire one more time (and only one more time) "

 

So the fix was to create a (hidden) field on the Lead object that gets arbitrarily updated every time a Lead is created. I created a checkbox and then a workflow rule that checks the box using a field update.

 

The beauty of this is that it allows the trigger to rerun as an UPDATE trigger to assign the lead properly even after the assignment rules have executed.  I left my trigger as a 'before insert, before update' trigger.

 

Hope this helps!

All Answers

bdr_09bdr_09

Hi,

   Did you get a solution for the web2lead owner issue. We are also facing same situation. Any input will be of great help. 

 

Thanks,

mhamberg1mhamberg1

I haven't gotten any feedback yet. I'm hoping there is a system control or some type of override indicator we can turn on.

 

Has anyone else found a fix for this?  I know that Salesforce has written triggers that can do what we're trying to do so it has to be possible.

mhamberg1mhamberg1

I finally figured this out! The clue was looking at Salesforce's order of execution found here.

 

The key is:


"10. If there are workflow field updates, the record is updated again

11. If the record was updated with workflow field updates, before and
after triggers fire one more time (and only one more time) "

 

So the fix was to create a (hidden) field on the Lead object that gets arbitrarily updated every time a Lead is created. I created a checkbox and then a workflow rule that checks the box using a field update.

 

The beauty of this is that it allows the trigger to rerun as an UPDATE trigger to assign the lead properly even after the assignment rules have executed.  I left my trigger as a 'before insert, before update' trigger.

 

Hope this helps!

This was selected as the best answer
Always ThinkinAlways Thinkin

Another solution for this specific scenario is to create a Lead Assignment Rule with one entry. In that entry, only check the Do Not Reassign Owner box, don't add any criteria. This negates the assignment of new Leads to the Default Lead Owner.

 

Note that this only works if you don't have other active Rules or entries. If you do have other active Rules, you will have to reconcile your triggers criteria and the Lead Assignment Rule criteria to determine where you insert the criteria-less entry to achieve the same effect.

Santro652Santro652

Thanks for this, its working for my team also. hats off to your idea. How did you get to know about this idea is something i am trying to understand..

I created a dummy assignment rule and it started to work.

BhagatBhagat

Big Thanks It totally work for me