You need to sign in to do that
Don't have an account?
Dan Carney 6
Get Started With Apex Exercise Problems
Hi. I'm having trouble with one of the exercises in the Get Started with Apex Triggers module, where you call a Class Method from a Trigger.
Here is the trigger I created.
trigger ExampleTrigger on Contact (after insert, after delete) {
if (Trigger.isInsert) {
Integer recordCount = Trigger.New.size();
// Call a utility method from another class
EmailManager.sendMail('dtcarney08@gmail.com', 'Trailhead Trigger Tutorial',
recordCount + ' contact(s) were inserted.');
}
else if (Trigger.isDelete) {
// Process after delete
}
}
This calls on this public class called EmailManager
public with sharing class EmailManager{
public static void sendMail(String[] addresses, String[] subjects, String[] messages) {
Messaging.SingleEmailMessage [] emails = new Messaging.SingleEmailMessage[]{};
Integer totalMails = addresses.size();
for(Integer i=0; i < totalMails; i++){
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setSubject(subjects[i]);
email.setToAddresses(new List<String> { addresses[i] });
email.setPlainTextBody(messages[i]);
emails.add(email);
}
Messaging.sendEmail(emails);
}
}
However, there is a problem that shows up in the Developer Console that says “Method does not exist or incorrect signature: void sendMail (String, String, String) from the type EmailManager. I thought that I made the method static and I'm not sure what's wrong now. Any ideas of what's wrong?
Here is the trigger I created.
trigger ExampleTrigger on Contact (after insert, after delete) {
if (Trigger.isInsert) {
Integer recordCount = Trigger.New.size();
// Call a utility method from another class
EmailManager.sendMail('dtcarney08@gmail.com', 'Trailhead Trigger Tutorial',
recordCount + ' contact(s) were inserted.');
}
else if (Trigger.isDelete) {
// Process after delete
}
}
This calls on this public class called EmailManager
public with sharing class EmailManager{
public static void sendMail(String[] addresses, String[] subjects, String[] messages) {
Messaging.SingleEmailMessage [] emails = new Messaging.SingleEmailMessage[]{};
Integer totalMails = addresses.size();
for(Integer i=0; i < totalMails; i++){
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setSubject(subjects[i]);
email.setToAddresses(new List<String> { addresses[i] });
email.setPlainTextBody(messages[i]);
emails.add(email);
}
Messaging.sendEmail(emails);
}
}
However, there is a problem that shows up in the Developer Console that says “Method does not exist or incorrect signature: void sendMail (String, String, String) from the type EmailManager. I thought that I made the method static and I'm not sure what's wrong now. Any ideas of what's wrong?
Your code is I think right. Are you testing it with "Anonymus Window" of Developer Console. If Yes then write here. So that we can discuss.