For Lead records coming from Marketing Cloud to SF I am triggering the default Lead Assignment Rules using APEX (method invoked from after Insert trigger on Lead).
/**
* Trigger Lead Assignment rules
*/
//this method is in the LeadTriggerHandler
private void triggerLeadAssignmentRules() {
List<Lead> leads = new List<Lead>();
for (Lead lead : triggerNew) {
//check if created by Marketing Cloud Integration User
if(lead.CreatedById == '00Q6F00001EC0yLUAT') {
leads.add(new Lead(Id = lead.Id));
}
}
if(!leads.isEmpty()) {
AssignLeadsUsingAssignmentRules.assignLead(leads);
}
}
//this method is in a separate service class named AssignLeadsUsingAssignmentRules
public static void assignLead(List<Lead> leadRecords) {
if(recursiveUpdate) {
return;
}
Database.DmlOptions dmlOptions = new Database.DmlOptions();
dmlOptions.assignmentRuleHeader.UseDefaultRule = true;
dmlOptions.EmailHeader.triggerUserEmail = true;
recursiveUpdate = true;
Database.SaveResult[] results = Database.update(leadRecords, dmlOptions);
recursiveUpdate = false;
}
Problem - Email checkbox is checked on Assignment rule entries, queue have send email to members checked, triggerUserEmail property on EmailHeader is set to true, however users in the queue aren't receiving any emails.
Is there something which i'm missing or I have to write custom logic to send email to queue members after the assignment rules are run ?