+ Start a Discussion
Deepak Sharma 184Deepak Sharma 184 

Getting an error ' constructors cannot be static'

public class EmailManager {
    
    public static sendEmail(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.SendEmailResult[] results = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
        inspectResults(results);
            
    }
    private static boolean inspectResults(Messaging.SendEmailResult[] results)
    {
        Boolean sendResult = true;
        
        for(Messaging.SendEmailResult res:results)
        {
            if(res.isSuccess())
            {
                System.debug('Email sent successfully');
            }
            else{
                sendResult=false;
                system.debug('The following errors occured: '+res.getErrors());
            }  
        }
        return sendResult;
    }
    }
    

 
Best Answer chosen by Deepak Sharma 184
JyothsnaJyothsna (Salesforce Developers) 
Hi,

Please update the  sendEmail() with return type void as below
 
public static  void sendEmail(String address, String subject, String body)

Hope this helps you!

Please mark the answer as Best Answer if it really helped so that it would help others as well in future.

Best Regards,
Jyothsna