
I need to send out notification emails of newly created tasks when I mass create/update them via the Apex Data Loader. My idea is the following setup:
- Custom checkbox field on Activity: isSendEmail__c
- Trigger to send emails
Now I am thinking of two options of which I don't know if one of those works (or if it works, how I do it):
- Iterate through tasks and manually create a SingleEmailMessage record and mass send them after iteration completes
- Somehow change the update/insert behaviour of the current trigger execution to do a Database.Insert / Database.Update with specified DML Options
Database.DMLOptions dmlOptions = new Database.DMLOptions(); dmlOptions.EmailHeader.TriggerUserEmail = true;// Database.insert(tasks, dmlOptions);
In any case, I want this to happen in a before trigger and I want in the same process uncheck the custom checkbox (in order to not trigger it again upon user task interaction)
I marked my main question in this thread in bold ;)Note: I do not want to use Processes / Workflows because those have known limitations which I do not want to worry about.
I have found traces of documentation about a "setOptions" function here:https://www.salesforce.com/us/developer/docs/dbcom_apex290/Content/apex_System_SObject_setOptions.htm I tried implementing it in my before trigger (which calls function below), but it seems the setOptions does not have an effect like this.
private void setDMLoptions()
{
// Enable sending tasks upon Task creation
Database.DMLOptions dmlOptions = new Database.DMLOptions();
dmlOptions.EmailHeader.TriggerUserEmail = true;
for ( Task t : tasks ) // tasks is a trigger.new list
{
if ( t.Send_Email__c )
{
t.setOptions(dmlOptions);
t.Send_Email__c = false;
}
}
}
Additional Info:
"Enable User Control over Task Assignment Notifications" is disabled