Find your content:

Search form

You are here

Errors trying to send email via Apex class

 
Share

I have a contact information section on a VF page. In this section, 'Email' is a field, and in another section I have a custom template. When I submit the page(via a Save button) I need to get the input of the 'Email' field and send an email with the custom template as the body.

Here is my code:

public void sendEmail(){ 
    Messaging.singleEmailMessage email1 = new Messaging.singleEmailMessage(); 
    String userEmail = new String(); 
    userEmail = Billing.Billingemail; 
    email1.setToAddresses(userEmail); 
    Messaging.sendEmailResult res = 
        Messaging.sendEmail(new Messaging.singleEmailMessage[] {email1}); 
    system.debug('resulttt'+res); 
} 

Getting error

Compile Error: Type cannot be constructed: String at line 771 column 27

Any ideas?

Note: I get the custom template through xml from another object.


Attribution to: Eagerin Sf

Possible Suggestion/Solution #1

You can't construct a string in that way - you can simply declare it and assign a value:

String userEmail=Billing.Billingemail;

however, you can reduce this further and simply pass the Billing.BillingEmail to the setToAddresses method of SingleEmailMessage as long as you wrap it up in an array:

email1.setToAddresses(new String[]{Billing.billingEmail});

Attribution to: Bob Buzzard
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/3858

My Block Status

My Block Content