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
MBouin__35devMBouin__35dev 

Method does not exist or incorrect signature: [Messaging.SingleEmailMessage].setToAddress(String)

Hello

 

I am setting up an Apex Class that will be used for sending an email, but I get the error that is mentioned in the subject

 

Thanks for your help

 

 

public class sendEmail {
public String subject { get; set; }
public String body { get; set; }
private final Playlist__c playlist;


// Create a constructor that populates the Account object
public sendEmail() {
playlist = [select Name,id,Contact__r.Email from Playlist__c where id = :ApexPages.currentPage().getParameters().get('id')];
}

public Playlist__c getPlaylist() {
return playlist;
}

public PageReference send() {
// Define the email
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
String address = playlist.Contact__r.Email;

// Sets the paramaters of the email
email.setSubject( subject );
email.setToAddresses( address);
email.setPlainTextBody( body );
// Sends the email
Messaging.SendEmailResult [] r =
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
return null;
}
}

 

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
visualforce_devvisualforce_dev
Make address a string array