function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nagamanohar Kavuri 9Nagamanohar Kavuri 9 

Can Some one Help on Below..Iam getting Error while Calling the EmailManager Class from Trigger

Email Manager Class
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 );
    }
}

Trigger :
trigger ExampleTrigger on Contact (after insert,after delete) {

    if(Trigger.isInsert)
    {
        Integer recordCount =Trigger.New.size();
        //Call utility method from another class
       EmailManager.sendMail('nmanoharsfdc@gmail.com','calling Class from trigger','my first task');
    }
    else if(Trigger.isDelete)
    {
        //Process after delete
    }
}

Error : Method does not exist or incorrect signature: void sendMail(String, String, String) from the type EmailManager
Best Answer chosen by Nagamanohar Kavuri 9
Meghna Vijay 7Meghna Vijay 7
Hi,
Instead of using EmailManager.sendMail('nmanoharsfdc@gmail.com','calling Class from trigger','my first task'); Use  EmailManager.sendMail(new String []{'nmanoharsfdc@gmail.com'}, new String[]{'calling Class from trigger'}, new String[]{'my first task'}); if you really need a list of string and if you think of creating a method with  public static  void sendMail(String addresses, String subjects, String messages), then use EmailManager.sendMail('nmanoharsfdc@gmail.com','calling Class from trigger','my first task');
Hope it help, if it does mark it as solved.
Thanks

All Answers

abhishek singh 497abhishek singh 497
Hello,
Nagamanohar,

Please use
  public static  void sendMail(String addresses, String  subjects, String  messages)  instead of  public static  void sendMail(String [] addresses, String [] subjects, String [] messages) 

Please let us know if this will help you.

Thanks & Regards,
Abhishek Singh.
Meghna Vijay 7Meghna Vijay 7
Hi,
Instead of using EmailManager.sendMail('nmanoharsfdc@gmail.com','calling Class from trigger','my first task'); Use  EmailManager.sendMail(new String []{'nmanoharsfdc@gmail.com'}, new String[]{'calling Class from trigger'}, new String[]{'my first task'}); if you really need a list of string and if you think of creating a method with  public static  void sendMail(String addresses, String subjects, String messages), then use EmailManager.sendMail('nmanoharsfdc@gmail.com','calling Class from trigger','my first task');
Hope it help, if it does mark it as solved.
Thanks
This was selected as the best answer
Nagamanohar Kavuri 9Nagamanohar Kavuri 9
Hi Abhishek,I tried to update what you said it is getting same error.Thankyou for your time

Hi Meghna :  I just updated the peice of code that you suggested,it is working. Thankyou for your time