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
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?

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

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

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


mail.saveAsActivity = false;

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

Thank you
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