2

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?

1
  • 3
    Problem is that you have class in class. Remove internal wrapper EmailManager
    – kurunve
    Feb 8, 2016 at 12:04

1 Answer 1

3

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 = '[email protected]';
String subject = 'Speaker Confirmation';
String body = 'Thank you for speaking at the conference.';
EmailManager.sendMail(address, subject, body);

I hope this will help.!

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .