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
PlainviewPlainview 

Assign Leads of Existing Accounts to Account Owner

Assignment Rule for New Leads for Existing Accounts. How?

Hello,

I would like to write either a lead assignment rule, workflow rule or Apex Trigger to accomplish this.

We would like our lead assignment, trigger and/or workflow rules to check if the lead's COMPANY already exists as an ACCOUNT, and therefore assign the new lead to the proper ACCOUNT OWNER.

Is there a formula that anyone can provide me to make this happen?

It would be great if the formula would look for CONTAINS "ACCOUNT NAME" rather than a direct match, for cases where a new lead submits their company name in a format slightly different than our existing ACCOUNT NAME.

Thank you greatly for your help.
Pavan Kumar KajaPavan Kumar Kaja
Hi,

Workflow or formula not work for you this case. You can achieve this using through trigger only. 
Swagato RaySwagato Ray
Hi ,

You can call the assignment rule from the trigger itself

like this

trigger LeadAssignmentTrigger on Lead (after update)

{

AssignmentRule AR = new AssignmentRule();

  private SforceService binding;

             Lead lead = new Lead();    
            AssignmentRuleHeader arh = new AssignmentRuleHeader();
            QueryResult qr = binding.query("Select Id from AssignmentRule where Name = " +
                "'Mass Mail Campaign' and SobjectType = 'lead'");
            if (qr.size == 0)
            {
                arh.useDefaultRule = true;
            }
            else
            {
                arh.assignmentRuleId = qr.records[0].Id;
            }
            binding.AssignmentRuleHeaderValue = arh;



}


PlainviewPlainview
HI Swagato! 

Thanks for your suggestion and it looks like something that could work. I am getting an error message when I try to create this trigger:

line 11:43 no viable alternative at character "'"

Any suggestions?

Thanks again,
Julien
Mike ChaputMike Chaput
Hi Plainview,

I am looking for the exact same trigger. Did you get a response regarding the error message?

Thanks

Mike

PlainviewPlainview
Hi Mike,

Sorrry for slow reply. Still working on this. Turns out this is a bigger issue than I realized. Am developing code (with help) but this issue seems to be a common problem without a viable solution - at least that's what my research is showing me.

When/if I do work it out, I will post it here - I promise!

Best,
Julien
KaedeKaede
Has anyone made any progress here? I am still searching for a solution. 
Melanie MaloneMelanie Malone
I am looking for this solution as well!
Pavan Kumar KajaPavan Kumar Kaja
Hi Melanie Malone,

Contact me pavanthetech@gmail.com
Nithya S 1Nithya S 1

Hi,

Was there a solution for this?

Thanks!