1

I'm working through the trailhead projects, and am currently on the one where I need to create a class to send an email (https://developer.salesforce.com/trailhead/project/salesforce_developer_workshop/creating_apex_class).

It's all pretty straight forward copy/paste stuff but I've run into a problem.

I'm on Step 3, using a static method and have the code copied from the site:

public class EmailManager {
    public with sharing class EmailManager{

        public static void sendMail(String address, String subject, String body) {
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            String[] toAddresses = new String[] {address};
            mail.setToAddresses(toAddresses);
            mail.setSubject(subject);
            mail.setPlainTextBody(body);
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        }
    }
}

And I'm then testing using the Execute Anonymous window using:

String address = 'kris@************.com';
String subject = 'Speaker Confirmation';
String body = 'Thank you for speaking at the conference.';
EmailManager.sendMail(address, subject, body);

Every time I try this, I get the error

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

Any suggestions?

  • 3
    Problem is that you have class in class. Remove internal wrapper EmailManager – kurunve Feb 8 '16 at 12:04
2

Apex class is written wrongly. Please find the below correct class & try one more time. It will work.

Apex Code:

public with sharing class EmailManager{
    public static void sendMail(String address, String subject, String body) {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {address};
            mail.setToAddresses(toAddresses);
        mail.setSubject(subject);
        mail.setPlainTextBody(body);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }
}

Calling in Execute Anonymous:

String address = 'contact@ajay-gupta.com';
String subject = 'Speaker Confirmation';
String body = 'Thank you for speaking at the conference.';
EmailManager.sendMail(address, subject, body);

I hope this will help.!

  • Great - thanks! I'm sure I'll get the hang of Apex sooner or later! – KrisReynolds Feb 8 '16 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.