You need to sign in to do that
Don't have an account?
Lead Trigger To Interrogate Lead Owner Status
Hello,
I've seen many related posts, but nothing that has pushed me over the top for this problem. Basically, I need a Lead trigger that can cause a Lead record to be run through the Lead Assignment rules if certain criteria are met on update of the Lead record.
One of the criteria is whether the current Lead Owner is an active or inactive SFDC user. I had written the code to capture the owner status field via a SOQL select statement, but unfortunately this logic causes the apparently common mistake of having too many SOQL queries because the select statement was inside the For loop in the trigger code.
Based on the other posts for that error, I know that I'll need to use Sets and Maps to get it to work, but has anyone written a similar trigger before?
Basically, I need to capture the value of the isActive flag on the user record that corresponds to the Lead owner for each Lead being evaluated by the trigger.
Any help is appreciated.
Thanks for your help guys.
I ended up getting this working with the code posted below. One thing that tripped me up was needing to avoid the attempt to get the user status if the Lead Owner was actually a Lead Queue.
All Answers
The above code is not tested. I guess you get the idea.
you can use the SOQL below to get the lead owner's Active flag for each lead being processed by the Trigger:
List<Lead> leadls = [select Id, Owner.IsActive from Lead where Id in: Trigger.newMap.keySet()];
Thanks for your help guys.
I ended up getting this working with the code posted below. One thing that tripped me up was needing to avoid the attempt to get the user status if the Lead Owner was actually a Lead Queue.