views:

131

answers:

1

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 notification 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.

A: 

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.

eyescream
The leads are not being assigned through an assignment rule. They are being assigned when some conditions are met in an update trigger. I am trying to avoid sending the email when the assignment is done through apex code.
lnediger
You must have "send email if..." logic somewhere. If not in assignment rule (are you sure? This is what is being used when you tick the checkbox while editing Lead), then probably in some Lead workflow. Or it's sent by some overlooked Apex code ;)
eyescream

related questions