I have a web-to-lead form setup, and it works fine. The default assignment is just set to my user, but I want to run a trigger to set the owner based on some criteria in custom fields I've created on the User
records. There are no other active assignment rules
The trigger runs when I hit the web-to-lead form, and doesn't have any errors, but when I check the newly created Lead record, the owner is still assigned to my user (the default for web-to-lead)?
I've tried changing the trigger from a before insert
to an after insert
both with the same result?
Before insert:
trigger SDRLeadQueue on Lead (before insert) {
system.debug('**** LEAD TRIGGER AFTER INSERT/UPDATE ****');
for(Lead lead : Trigger.new){
...
User sdrUser = sdrLeadQueueUsers.remove(0);
lead.OwnerId = sdrUser.id;
}
}
After insert (same logic, just need to select the lead/update it):
trigger SDRLeadQueue on Lead (after insert) {
system.debug('**** LEAD TRIGGER AFTER INSERT/UPDATE ****');
for(Lead lead : Trigger.new){
Lead newLead = [SELECT Id,OwnerId FROM Lead
WHERE id =: lead.id LIMIT 1];
...
User sdrUser = sdrLeadQueueUsers.remove(0);
newLead.OwnerId = sdrUser.id;
...
update newLead;
}
}