Prevent assignment email when assigning a lead with Apex
I have some code that automatically assigns a Lead to a Queue via a before Update trigger when certain conditions are met. When leads are assigned though the UI, the 'Send Assignment Notification' checkbox is available to specify whether or not to send a notifi开发者_C百科cation to the receiving user(Queue in this case).
l.OwnerId = groups.get('Lead Queue').Id;
This is how I am doing the assignment.
Is there any way to control this when assigning via Apex? It seems that by default an email is sent, which results in all members of the Queue receiving an email anytime a lead is auto-assigned to the Queue, which is not ideal.
Have you tried unchecking the "Send Email to Members" box in the Queue setup page? Maybe you need it for other reasons, but in our org, we've unchecked this box on many of our queues because we don't want the emails--just ownership. We use lead views, daily reports, and custom lead alerting for high priority leads instead.
We're using Marketo heavily for new leads mostly assigned to territory queues. I assume their code uses the API and sets OwnerId very much like your code example. We're not seeing the assignment notification emails plaguing your users though so I do think it's possible.
I don't think you can suppress the emails from assignment rules & workflows with Apex.
Email is sent because that's what you have specified in assignment rule (if you don't provide email template, it's not sent - https://na5.salesforce.com/help/doc/en/creating_assignment_rules.htm (replace na5 with your org instance).
But if you'll remove the email template from the rule, I think you still have some options to deal with it :)
You can build a workflow that will send email when criteria is met:
AND( OR( ISNEW(), ISCHANGED(OwnerId)), NOT("your criteria from Apex") )
(you'll need to set "Run this rule if the following: formula evaluates to true" in editor).
- You can build "after insert, after update" trigger (with same logical condition) that would send mail programatically. It's fairly easy & there are many examples.
If the logic you have in "before update" trigger is too complex to be covered with workflow (for example because it spans on several objects & queries) and #1 would be your preferred option, you still can do it. Simply use some custom hidden field in Lead and set it to "true" in your "before update" trigger, then check this value in the workflow.
Of course you could also disable the auto assignment rule completely, tell users that checkbox will be useless from now on and go with full workflow/full triggers solution, but that's a bit too invasive I think.
精彩评论