You need to sign in to do that
Don't have an account?
Inbox Outbox
Greetings! Code help please.
I am trying to send a mass welcome email (new customer template) to contacts after we save the contact. All I want is to know why I am getting the error and the solution for that.
I have the following code with an error. Please advice!
class:
public class massEmail
{
public void mail(){
list<contact> l= [SELECT ID FROM contact LIMIT 2];
list<ID> I= new list<ID>();
for(contact c: l){
I.add(C.Id);
}
EmailTemplate e = [SELECT ID FROM EmailTemplate WHERE Name = 'Sales: New Customer Email'];
messaging.MassEmailMessage m = new messaging.MassEmailMessage();
m.setTargetObjectIds(I);
m.setSenderDisplayName('System Admin');
m.setTemplateId(e.Id);
messaging.sendEmail(new messaging.MassEmailMessage [] {m});
}
}
Trigger:
trigger NewCustEmail on Contact (after insert)
{
if(trigger.IsAfter){
massEmail.mail(trigger.new);
}
}
Error:
Method does not exist or incorrect signature: void email(List<Contact>) from the type massEmail
I have the following code with an error. Please advice!
class:
public class massEmail
{
public void mail(){
list<contact> l= [SELECT ID FROM contact LIMIT 2];
list<ID> I= new list<ID>();
for(contact c: l){
I.add(C.Id);
}
EmailTemplate e = [SELECT ID FROM EmailTemplate WHERE Name = 'Sales: New Customer Email'];
messaging.MassEmailMessage m = new messaging.MassEmailMessage();
m.setTargetObjectIds(I);
m.setSenderDisplayName('System Admin');
m.setTemplateId(e.Id);
messaging.sendEmail(new messaging.MassEmailMessage [] {m});
}
}
Trigger:
trigger NewCustEmail on Contact (after insert)
{
if(trigger.IsAfter){
massEmail.mail(trigger.new);
}
}
Error:
Method does not exist or incorrect signature: void email(List<Contact>) from the type massEmail
Hi,
Yeah, I undestood
1. You need to make your method static like
2.You are not passing the argument in your method "mail()" but you are sending an argument from trigger "massEmail.mail(trigger.new);" . It is mandatory to pass argument in the method.
so you can correct your whole code like this:
if your query is solved please mark it as Best Answer
Thank You
All Answers
Hi
You are getting the error because your method is not accepting the parametre in apex class but you are passing parameter in trigger and hence the error.
Try updating the method as below :-
public class massEmail
{
public void mail(List<Contact> newList){
list<ID> I= new list<ID>();
for(contact c: newList){
I.add(c.Id);
}
EmailTemplate e = [SELECT ID FROM EmailTemplate WHERE Name = 'Sales: New Customer Email'];
messaging.MassEmailMessage m = new messaging.MassEmailMessage();
m.setTargetObjectIds(I);
m.setSenderDisplayName('System Admin');
m.setTemplateId(e.Id);
messaging.sendEmail(new messaging.MassEmailMessage [] {m});
}
}
Please mark it as Best Answer so that it can help others in the future.
Regards,
Priya Ranjan
You are not provided the method to static first you have to provide that method to static.I provided you the reference link for your convenience.
https://developer.salesforce.com/forums/?id=9060G000000Xa5DQAS
https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_email_outbound_mass.htm
If you find your answer mark as the best answer,
Thanks and Regards,
Suraj Tripathi.
Hi,
Yeah, I undestood
1. You need to make your method static like
2.You are not passing the argument in your method "mail()" but you are sending an argument from trigger "massEmail.mail(trigger.new);" . It is mandatory to pass argument in the method.
so you can correct your whole code like this:
if your query is solved please mark it as Best Answer
Thank You