You need to sign in to do that
Don't have an account?

SingleEmailMessage to Opportunity Owners
Hi Everyone,
I have been trying to create an Apex Controller that will allow users to click a "Send Email" button and have an email alert fire to the current opportunity owner AND all child opportunity owners. I keep getting the following error:
Method does not exist or incorrect signature: [Messaging.SingleEmailMessage].setToAddresses(List<Opportunity>) at line 25 column 4
Can someone explain how I can change the email addresses in my query to a list of String emails?
Thanks!
I have been trying to create an Apex Controller that will allow users to click a "Send Email" button and have an email alert fire to the current opportunity owner AND all child opportunity owners. I keep getting the following error:
Method does not exist or incorrect signature: [Messaging.SingleEmailMessage].setToAddresses(List<Opportunity>) at line 25 column 4
Can someone explain how I can change the email addresses in my query to a list of String emails?
Public with sharing class Sendemail{ public Opportunity Opp; public LIst<Opportunity> Oppty; public Sendemail(Apexpages.StandardController controller) { this.Opp=(Opportunity)controller.getRecord(); } Public void sendEmailFunction(){ List<Opportunity> Owners =[Select Owner.Email FROM Opportunity where Id=:opp.id OR Parent_Opportunity__r.Id=:opp.Id]; Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setToAddresses(Owners); mail.setReplyTo('myemail@mail.com'); mail.setSenderDisplayName('My Name'); mail.setPlainTextBody('A related Opportunity has been won'); mail.setHtmlBody('A related Opportunity has been won'); mail.setBccSender(false); mail.setUseSignature(false); //mail.setHtmlBody('<b> This is HTML body </b>' ); Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); } }
Thanks!
All Answers
Hi,
Add the owners emails to set<String> and pass it to setToAddresses().
www.infallibletechie.com
It accepts only String collection of array..and not more than 100
A list of email addresses to which you are sending the email. The maximum number of email addresses allowed is 100. This argument is allowed only when a template is not used.