You need to sign in to do that
Don't have an account?
Plainview
Assign Leads to default user in case of duplicate Accounts.
Hello,
I found this great code that is working (!!) for us now in our Production instance - it assigns new Leads to the Owners of matched Existing Accounts.
To level it up a bit, we would like the code to also route leads to a default user (who will function as the tiebreaker) when the lead is matched to two Account Records for the same company name that have different owners. Can anyone provide a quick line of logic that might do this?
Here's the code:
trigger addAccount on Lead (before Insert, before Update){
List<string> companies=new list<string>();
For (lead l:trigger.new){
companies.add(l.company);
}
List<Account> leadAccountIds=[Select Id, OwnerId, Name FROM Account WHERE Name IN: companies];
Map<String, Id> acctNameId=new Map<String, Id>();
Map<String, Id> acctNameOwner=new Map<String, Id>();
For (Account a:leadAccountIds){
acctNameId.put(a.name,a.Id);
acctNameOwner.put(a.name,a.ownerId);
}
For (Lead l2:trigger.new){
if(acctNameId.containsKey(l2.company)){
l2.Account__c=acctNameId.get(l2.company);
l2.ownerId=acctNameOwner.get(l2.company);
}
}
}
I found this great code that is working (!!) for us now in our Production instance - it assigns new Leads to the Owners of matched Existing Accounts.
To level it up a bit, we would like the code to also route leads to a default user (who will function as the tiebreaker) when the lead is matched to two Account Records for the same company name that have different owners. Can anyone provide a quick line of logic that might do this?
Here's the code:
trigger addAccount on Lead (before Insert, before Update){
List<string> companies=new list<string>();
For (lead l:trigger.new){
companies.add(l.company);
}
List<Account> leadAccountIds=[Select Id, OwnerId, Name FROM Account WHERE Name IN: companies];
Map<String, Id> acctNameId=new Map<String, Id>();
Map<String, Id> acctNameOwner=new Map<String, Id>();
For (Account a:leadAccountIds){
acctNameId.put(a.name,a.Id);
acctNameOwner.put(a.name,a.ownerId);
}
For (Lead l2:trigger.new){
if(acctNameId.containsKey(l2.company)){
l2.Account__c=acctNameId.get(l2.company);
l2.ownerId=acctNameOwner.get(l2.company);
}
}
}
All Answers
Climbing the learning curve,
J