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
Linked2MarkLinked2Mark 

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();
}
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_sendemail.htm

Example 2:- Please check below blog for step by step process
http://www.sfdc99.com/2014/03/01/sending-emails-using-apex/


Please let us know if this will help you.

Thanks
Amit Chaudhary