You need to sign in to do that
Don't have an account?
VDub
Method does not exist or incorrect signature Error on Trigger
Hi,
I'm getting an error on my trigger when I call the email class I created. The Line in red is the one causing the error.
I'm new to apex and any help would be appreciated .
Thanks, Vanessa
The Error
Method does not exist or incorrect signature: [AccCreatedEmailAlert].sendMail(LIST<Task>, SOBJECT:Task)
Class Code
public class AccCreatedEmailAlert{
public static void sendMail (User u, Task t) {
User u1 =[select Email from User where Id =: t.OwnerId limit 1];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddress = new String[] {u1.Email};
mail.setToAddresses(toAddress);
mail.setSubject('CS-Accommodation Order Task Created');
mail.setPlainTextBody('You are being sent this email because an CS-Accommodation Order Task has been created and assigned to you.\n\nThanks, SFDC');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
}
}
Trigger Code
I'm getting an error on my trigger when I call the email class I created. The Line in red is the one causing the error.
I'm new to apex and any help would be appreciated .
Thanks, Vanessa
The Error
Method does not exist or incorrect signature: [AccCreatedEmailAlert].sendMail(LIST<Task>, SOBJECT:Task)
Class Code
public class AccCreatedEmailAlert{
public static void sendMail (User u, Task t) {
User u1 =[select Email from User where Id =: t.OwnerId limit 1];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddress = new String[] {u1.Email};
mail.setToAddresses(toAddress);
mail.setSubject('CS-Accommodation Order Task Created');
mail.setPlainTextBody('You are being sent this email because an CS-Accommodation Order Task has been created and assigned to you.\n\nThanks, SFDC');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
}
}
Trigger Code
All Answers
Plus, you have a SOQL statement inside a loop - which is not adviseable.
It's totally working in Production. Thank you, Thank you, Thank you!!!
Here is the final code.
Class Code to Send Email to Owner of Task
public class AccCreatedEmailAlert {
public void sendMail (List<Id> userIds){
User[] usersToBlast = [select Email from User where Id =: userIds];
List<Messaging.SingleEmailMessage> messages = new List<Messaging.SingleEmailMessage>();
for (user u : usersToBlast){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddress = new String[] {u.Email};
mail.setToAddresses(toAddress);
mail.setSubject('CS-Accommodation Order Task Created');
mail.setPlainTextBody('You are being sent this email because an CS-Accommodation Order Task has been created and assigned to you.\n\nThanks, SFDC');
messages.add(mail);
}
Messaging.sendEmail(messages);
}
}
Trigger Code
trigger CSAccCreatedEmailAlert on Task (after insert) {
list<id> userIds = new list<Id>();
for (Task t : Trigger.new) {
if (t.Type == 'CS-Accommodation Order') {
userIds.add(t.OwnerId);
}
}
AccCreatedEmailAlert ac = new AccCreatedEmailAlert ();
ac.sendMail(userIds);
}
Test Class Code
@istest
public class TestCreatedTask {
static testMethod void insertNewTask(){
Task taskToCreate = new Task ();
taskToCreate.OwnerId = '00560000001GExO';
taskToCreate.Type = 'CS-Accommodation';
taskToCreate.Description = 'Please place Accommodation Order';
taskToCreate.Subject = 'Accommodation Order - Vanessa Pool and Spa';
taskToCreate.Status = 'Not Started';
taskToCreate.Priority = 'Normal';
insert taskToCreate;
}
}