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
Scott Seong 2Scott Seong 2 

Assign new lead to the original owner

We have a web-to-lead setup to create a new lead whenever a new Quote Request is made by web visitors regardless of where an email already exists in our SF instance. A new lead received from an existing customer will be treated as a new lead, and we would like to assign those existing customers to the same owner who service them before.

We've written a "before insert" trigger to search Account, Contact and non-converted Lead; and assign the newly created lead to the original owner. The trigger is working fine (from reviewing debug log).

We also have a Lead Assignment Rule, which uses "Lead Number" and "Round Robin ID" to assign leads to a selected few sales reps. The round robin rule works fine for new leads (non-duplicating email addresses), but for those existing emails assigned by the trigger (above) is reassigned by the Lead Assignment Rule.

Is there a way to create a Lead Assignment Rule, which bypasses the assignment if Owner already exists? We would like to keep the owner if it is already assigned by a trigger, and only assign via Round Robin rule if no owner is assigned by the trigger.

Any pointer is greatly appreciated.
 
Terence_ChiuTerence_Chiu
You could perhaps create a checkbox field on the Lead object labeled as "Bypass Assignment Rules" and from the code of your before insert trigger set the checkbox field to TRUE. You can then add a criteria in the assignment rules to only apply the rule if the checbox field value is FALSE.

I believe before triggers execute before assignment rules are applied (according to the order of executions provided by Salesforce (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm))so this may work for you.
Scott Seong 2Scott Seong 2
Thanks for the response. Your solution will work. Instead, I did the following to resolve the issue:

In the lead assignment rule, I created a first rule to check if AND(OwnerId<>null, OwnerID<>{ID of the default owner set in Lead Settings}). Having only (OwnerID, not equal to, null) rule end up assigning every lead to default owner. By combining, OwnerId<>null resolve the issue.

Thanks.
Scott Seong 2Scott Seong 2
I also had to check "Do Not Reassign Owner" in the step 3 of the Lead Assignment Rule. So, to summarize.

Step 1.  Sort Order = 1
Step 2.  Use "formula evaluates to true" with AND(OwnerId <> null, OwnerId <> {ID of the default owner set in Lead Settings}).
Step 3.  Check "Do Not Reassign Owner".
GWA MarketingGWA Marketing
May I know what edition of Salesforce you're using? Only enterprise and above allows you to add in those code that you've used right?