I am new to salesforce. I am practicing triggers. As a part of my learning, I wanted to send an email to the opportunity owner when an Opportunity is modified.
I wrote a trigger on Opportunity and passing trigger.new
to the below class.
I believe i have completed the below code except for an error that is popping up. It says
"Method does not exist or incorrect signature: void setToAddresses(User) from the type Messaging.SingleEmailMessage".
Can somebody help me, please?
public class Opportunitytriggerutility {
public void sendEmail(List<Opportunity> opps){
string temp_name = 'Opportunity Updated';
for(Opportunity op: opps){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
EmailTemplate et = [Select Id, Subject, Body from EmailTemplate where DeveloperName = 'Opportunity_Updated'];
mail.setToAddresses(op.Owner);
mail.setTemplateID(et.Id);
mail.setSubject(et.Subject);
mail.setHtmlBody(et.Body);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
}