I am stuck on this trigger.. i am trying to match Leads with existing accounts using a custom "domain" field. If an account exists with that same domain then i want to assign the incoming lead to the existing Account owner.
Here is my code so far, i am stuck on the last line, how do i get the account owner id?
trigger addAccount on Lead (before insert){
List<string> domain = new list<string>();
For (lead l:trigger.new){
domain.add(l.domain__c);
}
List<Account> leadAccountIds = [Select Id, OwnerId, domain__c FROM Account WHERE domain__c IN: domain];
Map<String, Id> acctNameId=new Map<String, Id>();
Map<String, Id> acctNameOwner=new Map<String, Id>();
For (Account a:leadAccountIds){
acctNameId.put(a.domain__c,a.Id);
acctNameOwner.put(a.domain__c,a.ownerId);
}
For (Lead l2:trigger.new){
if(acctNameId.containsKey(l2.domain__c)){
l2.ownerId=acctNameOwner.get(a.ownerID);
}
}
}