We need to set an email alert action in a workflow rule applied to a task object and I have read on Salesforce documentation that this type of action is not allowed on task workflow.

Is there any way to do that? The default functionality allows to send an email when you create a task but it is not possible to change the email notification format and content. Has anybody the same problem? Thanks in advance.

1 Answer 1


I'm not sure if anyone can come up with a native workaround, I do not know of one. You can accomplish this with a trigger if you are comfortable with Apex though. I know it's not ideal but at least you know its possible.

Something like this should work. Don't really know your use case so this is very simplified and you will have to set the body, subject, recipients, etc. based on your use case. This should get you started though.

trigger myTaskTrigger on Task (after insert) {

    set<Id> oppIDs = new set<Id>();
    for(Task t : trigger.new){
         if(t.What.Type == 'Opportunity'){

    map<Id, Opportunity> oppMap = new map<Id,Opportunity>([Select Id, Name From Opportunity Where Id In : oppIDs]); 

    List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
    for(Task t : trigger.new){

        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

        // create email content
        String subject = 'My Subject for the task email alert';

        String body = 'Here is where I can se the body of the email';

        // add recipients
        List<String> toAddresses = new List<String>();
        //Set your too addresses here based on task criteria

  • Hello sfdc_ninja, I have used your sample code but, the email is not sent. It is possible that it will be necessary add the email to the emails list? How can I do that?Thanks.
    – Guillermo
    Feb 13, 2014 at 15:53
  • Yes, this is not meant to be used as is. As I said, you need to actually add the email addresses to send the email to. Feb 13, 2014 at 16:19
  • Hello, now it is working. Just more question, how can I get information from the task parent object (an opportunity) to use in the email? thanks
    – Guillermo
    Feb 13, 2014 at 16:36
  • Just edited the answer. Now you have a map that contains the parent Opportunity records. All you need to do is add the appropriate fields you want for the opp into the SOQL query that is constructing the map. Feb 13, 2014 at 17:07
  • I was looking for something like this. Good answer....!!!
    – MANUELAN00
    Feb 24, 2016 at 0:08

You must log in to answer this question.

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