function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Del_SantosDel_Santos 

No Email Alert available for Task workflow

Hi,

 

I want to create a logic in salesforce that when a user created a task and saved will automatically send an email notification. When i tried creating a workflow, icannot find the email alert as immediate action. I only found outbound message which i am not sure if capable of doing so. If this outbound message will works for my requirement, can someone guide me on how should i begin. thanks.

 

Is there any way i can throw an email notification aside from this?

 

 

Thanks,
Del

Navatar_DbSupNavatar_DbSup

Hi,


You have to write a trigger on Task to achieve this in which you have to use the SingleEmailMessge method inside the trigger for sending an email. Try the below code as reference:
trigger WorkflowEmailFromOwner on Task (after insert) 


if (trigger.new.size() == 1 )

Contact con = [select id, c.Owner.Email, c.Owner.FirstName, c.Owner.LastName from Contact c where id = :trigger.new[0].whoid]; 

try{ 
EmailTemplate etemp = [select id from EmailTemplate where Name=:trigger.new[0].Subject and isactive=TRUE ]; 
messaging.Singleemailmessage mail=new messaging.Singleemailmessage(); 

mail.setSenderDisplayName(con.Owner.firstname +' '+ con.Owner.lastname); 
mail.setReplyTo(con.Owner.email); 
mail.setTargetObjectId(con.id); 
mail.setTemplateId(etemp.id); 
try

messaging.sendEmail(new messaging.Singleemailmessage[]{mail}); 
}
catch(DMLException e){

system.debug('ERROR SENDING FIRST EMAIL:'+e.getDMLMessage(0)); 

}catch(Exception Ex){ 
trigger.new[0].addError('Errors occured: '+Ex); 
system.debug(Ex); 

}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

Del_SantosDel_Santos

Hi,

 

Thanks for your reply.. My requirements is these:

1. On creating a tasks i have 4 different record type and of this is "Notice of Deactivation" record type.

I want to fire an email notification only if the task created is NOTICE OF DEACTIVATION.

 

2. Another problem is, i want to send email notice to people that has no salesforce account or user. sample: a group email: Finance@company.com.  Would this be possible?

 

 

Thanks in Advance!

 

Del

 

Navatar_DbSupNavatar_DbSup

Hi,

 

You can make additional condition inside the if which will check the record type=’ Notice of Deactivation’. So you consition should be like this:
if (trigger.new.size() == 1 && trigger.new[0].recordtypeid=’Pass the hard coded record type id of Notice of Deactivation ’)
2nd : You can create a custom field on activity which will contain all that mail id to which you want to send an email with comma separated value. Now split this text value inside the trigger and store inside the list of array and pass this list as setToAddresses of Singleemailmessage method.

Del_SantosDel_Santos

Hi,

Thanks a lot.

 

I have one more question, Can I also make it behave like a time based wf? if i want the email notice to fire 3 days before a specified time?

 

Thanks,

Del

Navatar_DbSupNavatar_DbSup

Hi,


For immediate action(I.e. when a activity is created or edited) you have to write the trigger on event or task. But if you are looking for functionality like time based workflow in that case you have to write a scheduled class.
Sales force provides the facility to schedule a class that will execute at particular time. And a class can be schedule only if it implements "Schedulable" interface. This interface has single method called "execute()".
Try the below code as reference:

global class testscheduled implements Schedulable
{
global void execute(SchedulableContext SC)
{
// place your custom logic here
}
}

To schedule that class goto setup --> App Setup--> Develop--> Apex Classes -- Click on "Schedule Apex" button
and select the class and time option as per your requirments.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

Jerun JoseJerun Jose

To add to Navatar's solution, you could schedule your logic thru a trigger. Check the section for 'Using the System.Schedule Method' in the link below.

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm

BAMBAM

I would like to use this Apex trigger or a variation so that a reminder (either the official Salesforce "reminder" or an unofficial reminder) can be sent BY EMAIL to the relevant person before the task is due. 

 

However, I am new to this.  How and where do I put an Apex trigger when I am in Salesforce?

 

Thanks for your help!

NaishaNaisha

Hi


For achieving the email alert functionality for task we just need to write below mentioned trigger OR we need to create Apex class alsoo

Saurabh DhobleSaurabh Dhoble

Check out this post to figure out how to send email alert for task updates.

Sarah MinihaneSarah Minihane

Hi

 

Can anyone help....

 

I am trying to create a workflow action in Salesforce under the object 'Task'. I want a workflow to be in place that if a task is not complete by the due date then an email is sent to the user that the task is assigned to to give them a prompt to complete the task. If a further 7 days later the task is still not complete then I want an email to be sent to the manager. 

 

I have tried to set this up but no Email Alert is available for Task Workflow - can anyone help on a work around for this or offer some coding for me to put in place. I am a trainee developer so would love to learn!

 

Thanks

 

Sarah 

Preston Galarneau06984696659637817Preston Galarneau06984696659637817
Navatar,

Almost there, but I am getting an error message, list has no rows for assignment to Sobject.

looks like 0 rows for email template Query?

What am I missing?
The_A-RodThe_A-Rod
As of the new Spring '16 release you can now create email alerts for activities (tasks and events). Once you create an email alert, you can add it to a process, workflow rule, milestone, approval process, or flow.