You need to sign in to do that
Don't have an account?

Problem with dmlo.EmailHeader.triggerUserEmail = true
Hi!
I wrote a trigger on Lead to create a task for the Lead owner and notify him about the task creation. Here is the code,
List<task> lNewTasks =new List<task>();
Database.DMLOptions dmlo = new Database.DMLOptions();
dmlo.EmailHeader.triggerUserEmail = true;
Task tsk = new Task(Subject = 'Follow Up Lead test',Ownerid = Lead.Owner.ID ,whoid =Lead.ID,ActivityDate=date.today().adddays(1), Type='Phone' );
database.insert(tsk, dmlo);
But facing following issues:
1) Sometimes email not sent out. I'm just not getting what is the logic for sending/not sending the email notification on task creation. An email should go out each time task is created with this logic.
2) In email body Lead Name is null. See:
New Task
To: Peter Carmasino
Shruti Gujarathi has assigned you the following new task:
Subject: Follow Up Lead
Lead: null
Due Date: 10/21/2014
Priority: Normal
For more details, click the following link:
https://ap1.salesforce.com/<Task.ID>
Can anyone help me into this? Why Lead is null in the email sent after task is created? We can not handle this email, so I don't know what else do I need to do in apex to have the Lead name in email?
Thanks in advance!!!
I wrote a trigger on Lead to create a task for the Lead owner and notify him about the task creation. Here is the code,
List<task> lNewTasks =new List<task>();
Database.DMLOptions dmlo = new Database.DMLOptions();
dmlo.EmailHeader.triggerUserEmail = true;
Task tsk = new Task(Subject = 'Follow Up Lead test',Ownerid = Lead.Owner.ID ,whoid =Lead.ID,ActivityDate=date.today().adddays(1), Type='Phone' );
database.insert(tsk, dmlo);
But facing following issues:
1) Sometimes email not sent out. I'm just not getting what is the logic for sending/not sending the email notification on task creation. An email should go out each time task is created with this logic.
2) In email body Lead Name is null. See:
New Task
To: Peter Carmasino
Shruti Gujarathi has assigned you the following new task:
Subject: Follow Up Lead
Lead: null
Due Date: 10/21/2014
Priority: Normal
For more details, click the following link:
https://ap1.salesforce.com/<Task.ID>
Can anyone help me into this? Why Lead is null in the email sent after task is created? We can not handle this email, so I don't know what else do I need to do in apex to have the Lead name in email?
Thanks in advance!!!
Also, are tasks begin created correctly on the Lead?
trigger NotifyLeadOwnerOnAssignment on Lead (after update)
{
try
{
list<Task> lNewTasks = new list<Task>();
Database.DMLOptions dmlo = new Database.DMLOptions();
dmlo.EmailHeader.triggerUserEmail = true;
if(Trigger.isupdate)
{
for(integer i=0; i<trigger.new.size(); i++)
{
system.debug('old owner@@@'+trigger.old[i].Ownerid);
system.debug('new owner@@@'+trigger.new[i].Ownerid);
if(trigger.old[i].Ownerid <> trigger.new[i].Ownerid )
{
Task tsk = new Task(Subject = 'Follow Up Lead',Ownerid = trigger.new[i].OwnerId ,whoid =trigger.new[i].Id,ActivityDate=date.today().addDays(1), Type='Phone' );
lNewTasks.add(tsk);
}
}
if(lNewTasks.size()>0)
database.insert(lNewTasks, dmlo);
}//if
}//try
catch(Exception e)
{
system.debug('InException'+e.getMessage());
}
}
Go to :
Setup > click Customize > Activities > Activity Settings>
Disable "Enable user control over task assignment notifications" at the org level
The team will also be updating you via the case of the same - putting it here to help others who might be facing a similar issue..
We also had similar issue in production. so we tried to implement the workaround suggested by you. It works in DEV and ST enviroment whereas in UAT enviroment it throws the error "You can’t edit the Activity Settings page now because there’s a Shared Activities update in progress. Try again later."