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 Patterson 3Scott Patterson 3 

Creating trigger to assign lead owners based on web domain

Hi, I'm very new to SFDC development and am trying to create a trigger that will assign lead owners based on web domain (lead field name = "rWeb Domain"). Currently, lead ownership is defined at the company level (i.e. one company is owned by one user), and we uniquely identify a company by its rWeb Domain. I'm hoping to automatically assign any newly created leads where the company already exists in SFDC to the appropriate lead owner. For any new leads where no company exists, I'd like to assign them to lead owners based on a round-robin system, but with a qualifier for Inudstry. Our users are currenlty segmented into two teams, each with different Industries (team 1 Industries = "Education", "Technology"; Team 2 Industries = "Media", "Entertainment"). As such, the round robin lead assignments should apply to new leads within those respective industries. All other new leads (i.e. those where no matching rWeb Domain exists AND that do not fall into one of those four industries) should be assigned to me.

Any help would be much appreciated! Thanks!
There are 2 ways to to this, one is more flexiable then the other.

1. Use Salesforce OOB Lead Assignment rule to define rule based on the Company type but it has to match the rule condition, also if the number of unique company increase then its not scalable. As you already have one user handlink one company it should work for some extent.

2. Use a custom trigger and write all your logic there( have a object to hold company name with respect to user name), if no criteria for company meets then move to Industry check the so on.

Hope this give some idea to start.
Scott Patterson 3Scott Patterson 3
Thanks neao and Venu. It definitely seems like a custom trigger is what I'll need to implement here. The tricky part is that the inputs here are not static. When a new lead is created, the following needs to take place:

1. The lead's web domain field (a custom field called "rWeb Domain") needs to be checked against all current leads to see if that rWeb Domain already exists.
  • if the rWeb Domain value does already exist, the lead owner should be assigned to existing lead owner mapped to that rWeb Domain
  • if the rWeb Domain value does not already exist, assignment rules should be based on logic in step 2
2. (only needed if step 1 is not validated) The lead's "Industry" field should be checked using the following criteria to determine which owner to assign to:
  • If Industry = 'Education' OR 'Technology', assign (round robin) to owner on team 1
  • If Industry = 'Media' OR 'Entertainment', assign (round robin) to owner on team 2
  • If Industry = anything else, assign to me

So far, most of the reference material I've found is centered around building out lead owner assignment code to particular owners based on static variables (e.g. assign leads to UserA when lead source = 'Web'). I'm hoping to figure out how to make this much more dynamic while being able to reference existing lead data.