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
Coral RacingCoral Racing 

Add a receipeint to a VisualForce Email Template?

Hi

I am trying to write a trigger to allow me to pass into an email template so that a particular recipient gets this email everytime it is used.  So far I have gotten thus far:
trigger SingleEmail on Opportunity (before insert) {
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 
    toAddresses = new String[] {'Joeblogg@abc123'};
            email.setToAddresses(toAddresses);     
EmailTemplate template = new EmailTemplate();
            template = [select Id from EmailTemplate where Name = 'P1_Incident_Update_Template_1'];
            mail.setTemplateID(template.Id);
}

I am getting an error on line 3 though stating that variable unknown:toaddressess

Can anyone see what I am doing wrong and indeed if this is the right way to go about resolving my over all requirement dilemma?

Thanks

Sonya
Anoop yadavAnoop yadav
Hi,

Try by using a valid Email Address At line 3.
Coral RacingCoral Racing
Hi  - Thanks for getting back to me.  Yes I tried that to no avail
Anoop yadavAnoop yadav
Hi,

You did not define the variable.

Use "String[] toAddresses = new String[] {'Joeblogg@abc123.com'};"
at Line 3

Anoop yadavAnoop yadav
Hi,

You can also try the below one.

trigger SingleEmail on Opportunity (before insert) {
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 
    mail.setToAddresses( new String[] {'Joeblogg@abc123.com'});     
EmailTemplate template = new EmailTemplate();
            template = [select Id from EmailTemplate where Name = 'P1_Incident_Update_Template_1'];
            mail.setTemplateID(template.Id);
}

Coral RacingCoral Racing
Great thanks - there were no problems detected.  Although now when I select the template it doesn't cc the specifiec email address in