1

I have 2 Users that belong to the queue 'Sales' with the Send Email to Members checked.

I have an online app that creates a new lead, and sets various lead fields, but the email is not sent to members of the queue. Code:

Lead l = new Lead();  
...  
l.OwnerId = [Id of Sales Queue];  
Database.DMLOptions dmlOpt = new Database.DMLOptions();  
dmlOpt.EmailHeader.triggerUserEmail = true;  
database.insert(l, dmlOpt);

I am aware that there is another option to use default assignment rules which would reassign the queue and send the email to the queue members, however I do not want assignment rules to be evaluated, I only want to send the email to the member of the queues upon insert.

Why is no email sent?

3 Answers 3

1

You can configure a workflow rule on Lead object which will fire during creation only. And in the workflow action, send email to the Lead owner.

This email should go to all the queue members if owner is queue otherwise, it will go the user.

2
  • 1
    I only want the email sent for leads that are inserted by the app, not all leads that are inserted, any ideas?
    – ZeeDawg
    May 10, 2018 at 17:34
  • 1
    Create a checkbox in Lead object and mark it true during insert from App. Use that checkbox as selection criteria to send email May 10, 2018 at 17:35
1

A solution I found to this problem was:
- insert the lead without specifying the Owner
- subsequently update the owner to the appropriate queue using

database.update(l, dmlOpt);

This resulted in an email being sent to the queue members.

0

Two things I can share with you all guys.

  1. To set "AssignmentRuleHeader" to invoke assignment rule use below code

Database.DMLOptions dmo = new Database.DMLOptions(); dmo.assignmentRuleHeader.useDefaultRule= true;

Lead l = new Lead(// create lead record);

l.setOptions(dmo); insert l;

  1. Like wise to set "EmailHeader" to true so that system triggers email notification when lead is created through API then use below code in conjunction of above code.

Database.DMLOptions dmo = new Database.DMLOptions(); dmo.assignmentRuleHeader.useDefaultRule= true; Dmo.EmailHeader.triggerUserEmail = true;

Lead l = new Lead(// create lead record);

l.setOptions(dmo); insert l;

Both assignment rule as well as email will work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .