You need to sign in to do that
Don't have an account?
Gita Borovsky
Can't figure out where to put my line of code
I have a bit of code that checks to see if an account already exists based on a domain and reassigns the incoming lead based on Account owner. I need to update the trigger to leave a particular Account Owner Role out of the process but I can't figure out where to put the code. Any help would be appreciated, thanks! Here's the owner role id: 00E50000000t0Bf and here's the trigger:
trigger UpdateLeadOwner on Lead (before insert) {
for (Lead leadInLoop : Trigger.new) {
if (leadInLoop.LeadSource != 'Contact Us' && leadInLoop.LeadSource != 'Reprint') {
// Retrieve owner from Account record based on email domain name
list <Account> acct = [Select OwnerId from Account WHERE Domain_1__c = :leadInLoop.Domain__c Limit 2];
if (acct.size() == 1) {
//the next line is for debugging, to check that you are getting a result back from the query
System.debug('account owner id is: ' + acct[0].OwnerId);
leadInLoop.OwnerId=acct[0].OwnerId;
}
}
}
}
trigger UpdateLeadOwner on Lead (before insert) {
for (Lead leadInLoop : Trigger.new) {
if (leadInLoop.LeadSource != 'Contact Us' && leadInLoop.LeadSource != 'Reprint') {
// Retrieve owner from Account record based on email domain name
list <Account> acct = [Select OwnerId from Account WHERE Domain_1__c = :leadInLoop.Domain__c Limit 2];
if (acct.size() == 1) {
//the next line is for debugging, to check that you are getting a result back from the query
System.debug('account owner id is: ' + acct[0].OwnerId);
leadInLoop.OwnerId=acct[0].OwnerId;
}
}
}
}
All Answers