+ Start a Discussion

In Getting Started with Apex

I am working through the SendEmail example and can't get my code to run. Can't figure out why. 
I copied the code out of the example - removing all of the line numbers - into EmailManager.apxc
I copied the following Apex code into and anonymous debug window: 
EmailManager em = new EmailManager();
em.sendMail('myemailaddress@gmail.com', 'Trailhead Tutorial', '123 body');

Window opens with the message:

Line: 2, Column: 1
Method does not exist or incorrect signature: [EmailManager].sendMail(String, String, String)

It cant see my method for some reason - any tips?

Amit Chaudhary 8Amit Chaudhary 8
Please try below code. I hope that will help you
Example 1:- Email with Attachment

Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setToAddresses(new String[] { 'admin@acme.com' });
email.setSubject('my subject');
email.setPlainTextBody('plain text body');
List<Messaging.SendEmailResult> results = 
    Messaging.sendEmail(new Messaging.Email[] { email });
if (!results.get(0).isSuccess()) {
    System.StatusCode statusCode = results.get(0).getErrors()[0].getStatusCode();
    String errorMessage = results.get(0).getErrors()[0].getMessage();

Example 2:- Please check below blog for step by step process

Please let us know if this will help you.

Amit Chaudhary