+ Start a Discussion
admin awadmin aw 

Trigger to send email notification when a task is auto created by specific user

Hi, We have integration with marketing software and SF. Task is auto create for lead/contact owner by the specific user "Marketing".
When a task is created by this user, I'd like an email notification to go out to the task owner.
But when I try to get this trigger working, system gives me syntax errors. Can somebody help please?

If
( Task.CreatedByID == '00520000001WZwB' && Task.Status = 'Started')
{

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String emailid = Task.Owner.Email;

String[] toAddresses = new String[] {emailid};

mail.setToAddresses(toAddresses);
mail.setSenderDisplayName('Marketing');

mail.saveAsActivity = false;
mail.setTargetObjectId(Task.ID);
mail.setTemplateId('00Xg0000000DnJl');
mail.setUseSignature(false);
mail.setSaveAsActivity(false);

Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}

Thank you
Sonam_SFDCSonam_SFDC
In line 2, the IF statement has an assignment instead of  comparision:

Task.CreatedByID == '00520000001WZwB' && Task.Status = 'Started'

should be

Task.CreatedByID == '00520000001WZwB' && Task.Status == 'Started'

rest code looks ok -


sourav rajaksourav rajak
hello admin,
can u please help me by providing the whole code and also the process how and where to execute it  beacause i also want to the the thing that you were looking for