1

I've got an Apex trigger that automatically converts incoming leads if certain conditions are met. These leads are themselves added to the system via an API call from my main application. I've also got a set of lead assignment rules for assigning leads to members of my sales team.

Ideally, then, a customer would fill out an application on my site, be added to Salesforce as a lead, be assigned to one of my sales team, and then be converted to an opportunity. The opportunity would then be owned by the appropriate sales team member.

The problem is that I am often seeing the converted opportunities not being assigned to the same sales person as the lead. It looks like the assignment rules are not run at all: the opportunity is owned by the default assignee of the lead. But I look at the converted lead and it is assigned to one of my sales people - so the conversion to opportunity does not carry over the assignment.

I suspect there is a race condition going on between the lead assignment rule and the automatic conversion of the leads.

Can anyone suggest a solution?

Thanks, Joe

0

If you look at the Order of execution for SF found here, you can see that assignment rules are fired after the triggers. Triggers are in step 3 & 7, while assignment rules are in step 8. Since you are converting the leads to opportunities in your trigger, the assignment rules are never run since they are converted by the time they hit the assignment rules.

You can either try to move the assignment of the opportunity logic into your trigger, or try to do the auto conversion logic after the assignment rules have run, like in a trigger on the lead after the owner changes.

  • When faced with this issue before, I used sfdc_ninja's solution: try to do the auto conversion logic after the assignment rules have run, like in a trigger on the lead after the owner changes – cropredy Jan 29 '15 at 17:45
  • Any pointers on how to write a trigger that fires after the owner changes? – Joe Dzikiewicz Jan 30 '15 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.