0

When running the following code I get this error message:

[Messaging.SingleEmailMessage].setToAddressof(List)

public class outboundemail1 {
    public void sendMail(){
        String[] toadd = new String[]{'[email protected]'};
        String[] toCc = new String[]{'[email protected]'};
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        email.setToAddress(toadd);
        email.setCcAddresses(tocc);
        email.setSubject('Hi from salesforce sender bhavani');
        email.setPlainTextBody('Welcome to Salesforce Email for the first time');
        Messaging.SingleEmailMessage email2=new Messaging.SingleEmailMessage();
        email2.setToAddress(toadd);
        email2.setSubject('HTML Body');
        email2.setHTMLBody('<h1style="colour:green">Welcome to Salesforce Email for the first time</h1>');
        email2.setSenderDisplayName('bhavani818584884');
        Messaging.Email[] emails = new Messaging.Email[] {email,email2};
        Messaging.SendEmail(emails);
    }
}

This is the code of my visualforce page:

<apex:page OutboundEmail1 ot=new OutboundEmail1> ot.sendMais(); </apex:page>
4
  • 1
    Can you be more precise about the error? What's the name of the method which doesn't exist? And provide us your visualforce page. Commented Jan 10, 2017 at 13:57
  • this is the error shows as[Messaging.SingleEmailMessage].setToAddressof(List) Commented Jan 10, 2017 at 14:10
  • <apex:page OutboundEmail1 ot=new OutboundEmail1> ot.sendMais(); </apex:page> this is my visualforcepage Commented Jan 10, 2017 at 14:11
  • martin lezer did u got my problem?thnq for ur quick responds Commented Jan 10, 2017 at 14:12

2 Answers 2

3

As you can see in the Salesforce documentation about the SingleEmailMessage class, there is no setToAddress method. Its name is: setToAddresses.

0

In your method you've wrote:

email.setToAddress(toadd);

There's a slight typo in that the method you want is:

email.setToAddresses(toadd);

Note the extra "es" in the method name.

1
  • yeah got it,Thank you Martin Lezer for giving solution to my problem,i am done with that thnk u soo much :-) Commented Jan 10, 2017 at 14:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .